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

#include<stdio.h> main() { register i=5; char j[]= "hello"; printf("%s %d",j,i); }

2 Answers  


How to swap two variables, without using third variable ?

104 Answers   AB, ADP, BirlaSoft, Cisco, Cygnet Infotech, HCL, Hewitt, Honeywell, HP, IBM, Infosys, Manhattan, Microsoft, Mobius, Percept, Satyam, SofTMware, TCS, Wipro, Yamaha,


void main() { int i=5; printf("%d",i+++++i); }

3 Answers  


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

1 Answers  


main(int argc, char *argv[]) { (main && argc) ? main(argc-1, NULL) : return 0; } a. Runtime error. b. Compile error. Illegal syntax c. Gets into Infinite loop d. None of the above

4 Answers   HCL, LG,






main() { char str1[] = {‘s’,’o’,’m’,’e’}; char str2[] = {‘s’,’o’,’m’,’e’,’\0’}; while (strcmp(str1,str2)) printf(“Strings are not equal\n”); }

1 Answers  


main() { int i = 3; for (;i++=0;) printf(“%d”,i); }

1 Answers   CSC,


Link list in reverse order.

8 Answers   NetApp,


main() { int i=300; char *ptr = &i; *++ptr=2; printf("%d",i); }

4 Answers   CSC,


#define max 5 #define int arr1[max] main() { typedef char arr2[max]; arr1 list={0,1,2,3,4}; arr2 name="name"; printf("%d %s",list[0],name); }

1 Answers  


How can you relate the function with the structure? Explain with an appropriate example.

0 Answers  


What is the problem with the following code segment? while ((fgets(receiving array,50,file_ptr)) != EOF) ;

1 Answers  


Categories