char *p="GOOD";

char a[ ]="GOOD";

printf("\n sizeof(p) = %d, sizeof(*p) = %d, strlen(p) = %d",
sizeof(p), sizeof(*p), strlen(p));

printf("\n sizeof(a) = %d, strlen(a) = %d",
sizeof(a), strlen(a));


main() { char *p="GOOD"; char a[ ]="GOOD"; printf(&qu..

Answer / susie

Answer :

sizeof(p) = 2, sizeof(*p) = 1, strlen(p) = 4

sizeof(a) = 5, strlen(a) = 4


sizeof(p) => sizeof(char*) => 2

sizeof(*p) => sizeof(char) => 1


sizeof(a) => size of the character array => 5

When sizeof operator is applied to an array it returns the
sizeof the array and it is not the same as the sizeof the
pointer variable. Here the sizeof(a) where a is the
character array and the size of the array is 5 because the
space necessary for the terminating NULL character should
also be taken into account.

Is This Answer Correct ?    1 Yes 1 No

Post New Answer

More C Code Interview Questions

What is the match merge ? compare data step match merge with proc sql merge - how many types are there ? data step vs proc sql

0 Answers  

#define square(x) x*x main() { int i; i = 64/square(4); printf("%d",i); }

4 Answers   Google, HCL, Quick Heal, WTF,

#include<stdio.h> main() { const int i=4; float j; j = ++i; printf("%d %f", i,++j); }

1 Answers  

struct point { int x; int y; }; struct point origin,*pp; main() { pp=&origin; printf("origin is(%d%d)\n",(*pp).x,(*pp).y); printf("origin is (%d%d)\n",pp->x,pp->y); }

1 Answers  

main() { char *p; p="%d\n"; p++; p++; printf(p-2,300); }

1 Answers  

#include"math.h" void main() { printf("Hi everybody"); } if <stdio.h> will be included then this program will must compile, but as we know that when we include a header file in "" then any system defined function find its defination from all the directrives. So is this code of segment will compile? If no then why?

2 Answers  

What are the files which are automatically opened when a C file is executed?

1 Answers  

You are given any character string. Find the number of sets of vowels that come in the order of aeiou in the given string. For eg., let the given string be DIPLOMATIC. The answer returned must be "The number of sets is 2" and "The sets are "IO and AI". Vowels that form a singleton set must be neglected. Try to post the program executable in gcc or g++ or in java.

3 Answers  

Finding a number which was log of base 2

1 Answers   NetApp,

Program to Delete an element from a doubly linked list.

4 Answers   Infosys, College School Exams Tests,

Write a program to receive an integer and find its octal equivalent?

7 Answers  

why java is platform independent?

12 Answers   Wipro,