Is the following code legal?

struct a

{

int x;

struct a *b;

}

Answers were Sorted based on User's Feedback



Is the following code legal? struct a { int x; struct..

Answer / susie

Answer :

Yes.

Explanation:

*b is a pointer to type struct a and so is legal. The
compiler knows, the size of the pointer to a structure even
before the size of the structure

is determined(as you know the pointer to any type is of same
size). This type of structures is known as
‘self-referencing’ structure.

Is This Answer Correct ?    2 Yes 0 No

Is the following code legal? struct a { int x; struct..

Answer / pavan_mustyala

The code snippet is absolutely valid and this concept which
is comes under "self- referential" concept is used to
develop linked lists.

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More C Code Interview Questions

to remove the repeated cahracter from the given caracter array. i.e.., if the input is SSAD output should of SAD

6 Answers   Synergy,


main() { int i=400,j=300; printf("%d..%d"); }

3 Answers  


All the combinations of prime numbers whose sum gives 32

1 Answers   HHH,


int main() { int x=10; printf("x=%d, count of earlier print=%d", x,printf("x=%d, y=%d",x,--x)); getch(); } ================================================== returns error>> ld returned 1 exit status =================================================== Does it have something to do with printf() inside another printf().

1 Answers  


main() { char not; not=!2; printf("%d",not); }

1 Answers  






WAP to display 1,2,3,4,5........N

2 Answers  


main( ) { int a[ ] = {10,20,30,40,50},j,*p; for(j=0; j<5; j++) { printf(“%d” ,*a); a++; } p = a; for(j=0; j<5; j++) { printf(“%d ” ,*p); p++; } }

1 Answers  


main() { int a=10,*j; void *k; j=k=&a; j++; k++; printf("\n %u %u ",j,k); }

1 Answers  


create a C-code that will display the total fare of a passenger of a taxi if the driver press enter,the timer will stop. Every 10 counts is 2 pesos. Initial value is 25.00

0 Answers   Microsoft,


main( ) { void *vp; char ch = ‘g’, *cp = “goofy”; int j = 20; vp = &ch; printf(“%c”, *(char *)vp); vp = &j; printf(“%d”,*(int *)vp); vp = cp; printf(“%s”,(char *)vp + 3); }

1 Answers  


void main() { int *i = 0x400; // i points to the address 400 *i = 0; // set the value of memory location pointed by i; }

2 Answers  


Give a very good method to count the number of ones in a 32 bit number. (caution: looping through testing each bit is not a solution)

7 Answers   Microsoft,


Categories