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.

Aditya Verma said:   4 months ago
@Vishwajeet Jadhav.

Here it's mentioned 32 bits that means 4Byte of pointer size is correct.

M.guna said:   5 years ago
While we finding the string length we didn't count null right?

Please anyone explain it.
(1)

Kareena said:   5 years ago
@M.Guna:

Yes, during string length, we don't count null.
But in sizeof, we count null.
(1)

Shibu said:   1 decade ago
The size of b is 4 bytes, however *b is pointing to 1st character, so its size is 1.

Vivek said:   1 decade ago
@Uttam

Since b is a pointer, it holds a size of 4 bytes. As given in the question.

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

Madhumita said:   1 decade ago
Size of every pointer variable is 2 byte then how the size of b is 4byte ?

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

Rekha said:   8 years ago
When I compile I got,

11,8
1,1.

Anyone clear my doubt.
(1)

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.