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;
}
Discussion:
30 comments Page 2 of 3.
Shehnaz said:
8 years ago
Thanks for the given description.
Mansi said:
9 years ago
But why *a and *b points to the first character of word?
Shital said:
9 years ago
Thank you guys. I understand completely!
Akash said:
9 years ago
You guys are explained superbly. Thank you!
Rockz said:
10 years ago
I didn't get this!
Pranay airan said:
1 decade ago
Char a[] has 10 letters and 1 escape character /0 so size of will give 11, size of pointer is 32 bit = 4 byte (1 byte = 8 bits), *a points to char V so sizeof(V) = 1 similarly *b also points to V.
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.
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.
Awanish said:
1 decade ago
How you people are saying that a[] having 10 letters.
Here 8 letter are given including + sign.
Here 8 letter are given including + sign.
Gurchet said:
1 decade ago
@Sonu.
We don't include null in size of string.
We don't include null in size of string.
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?
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers