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

what is variable length argument list?

2 Answers  


write a c program to Create a mail account by taking the username, password, confirm password, secret_question, secret_answer and phone number. Allow users to register, login and reset password(based on secret question). Display the user accounts and their details .

2 Answers  


Write a Program that Inputs 10 Numbers in an Array and Show the Maximum Number

2 Answers   Ace Info,


#include<stdio.h> main() { int a[2][2][2] = { {10,2,3,4}, {5,6,7,8} }; int *p,*q; p=&a[2][2][2]; *q=***a; printf("%d----%d",*p,*q); }

1 Answers  


main() { extern int i; { int i=20; { const volatile unsigned i=30; printf("%d",i); } printf("%d",i); } printf("%d",i); } int i;

1 Answers  






int i; main(){ int t; for ( t=4;scanf("%d",&i)-t;printf("%d\n",i)) printf("%d--",t--); } // If the inputs are 0,1,2,3 find the o/p

2 Answers  


func(a,b) int a,b; { return( a= (a==b) ); } main() { int process(),func(); printf("The value of process is %d !\n ",process(func,3,6)); } process(pf,val1,val2) int (*pf) (); int val1,val2; { return((*pf) (val1,val2)); }

1 Answers   Satyam,


#define SQR(x) x * x main() { printf("%d", 225/SQR(15)); } a. 1 b. 225 c. 15 d. none of the above

3 Answers   HCL,


main() { if (!(1&&0)) { printf("OK I am done."); } else { printf("OK I am gone."); } } a. OK I am done b. OK I am gone c. compile error d. none of the above

3 Answers   HCL,


void main() { if(~0 == (unsigned int)-1) printf(“You can answer this if you know how values are represented in memory”); }

1 Answers  


All the combinations of prime numbers whose sum gives 32

1 Answers   HHH,


void pascal f(int i,int j,int k) { printf(“%d %d %d”,i, j, k); } void cdecl f(int i,int j,int k) { printf(“%d %d %d”,i, j, k); } main() { int i=10; f(i++,i++,i++); printf(" %d\n",i); i=10; f(i++,i++,i++); printf(" %d",i); }

1 Answers  


Categories