C Programming - Strings - Discussion

Discussion Forum : Strings - Find Output of Program (Q.No. 17)
17.
If the size of pointer is 32 bits What will be the output of the program ?
#include<stdio.h>

int main()
{
    char a[] = "Visual C++";
    char *b = "Visual C++";
    printf("%d, %d\n", sizeof(a), sizeof(b));
    printf("%d, %d", sizeof(*a), sizeof(*b));
    return 0;
}
10, 2
2, 2
10, 4
1, 2
11, 4
1, 1
12, 2
2, 2
Answer: Option
Explanation:
No answer description is available. Let's discuss.
Discussion:
30 comments Page 2 of 3.

Sumit said:   1 decade ago
Here *a is not declared anywhere so it would calculate sizeof (*a) please explain.

Smruti said:   1 decade ago
Any one can help how the 1st printf statement work. I want to say that size(a) means length of a or sizeof datatype of a?

Gurchet said:   1 decade ago
@Sonu.

We don't include null in size of string.

Awanish said:   1 decade ago
How you people are saying that a[] having 10 letters.

Here 8 letter are given including + sign.

Ankit verma said:   1 decade ago
I am sending answer to @Awanish.

If you initialized anything in string so it is not worry about ++. Because + sign is not a sign, it is a character at that time.

New coder said:   10 years ago
Can anyone explain why its giving error? If program is correct.

Rockz said:   10 years ago
I didn't get this!

Akash said:   9 years ago
You guys are explained superbly. Thank you!

Shital said:   9 years ago
Thank you guys. I understand completely!

Mansi said:   9 years ago
But why *a and *b points to the first character of word?


Post your comments here:

Your comments will be displayed after verification.