Is the following code legal?
struct a
{
int x;
struct a *b;
}
Answers were Sorted based on User's Feedback
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 |
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 |
main() { char *p = “ayqm”; char c; c = ++*p++; printf(“%c”,c); }
main() { int i, n; char *x = “girl”; n = strlen(x); *x = x[n]; for(i=0; i<n; ++i) { printf(“%s\n”,x); x++; } }
#include<stdio.h> main() { struct xx { int x; struct yy { char s; struct xx *p; }; struct yy *q; }; }
main() { register int a=2; printf("Address of a = %d",&a); printf("Value of a = %d",a); }
main() { int x=5; clrscr(); for(;x<= 0;x--) { printf("x=%d ", x--); } } a. 5, 3, 1 b. 5, 2, 1, c. 5, 3, 1, -1, 3 d. –3, -1, 1, 3, 5
void main() { static int i; while(i<=10) (i>2)?i++:i--; printf(“%d”, i); }
Given an array of characters which form a sentence of words, give an efficient algorithm to reverse the order of the words (not characters) in it.
what is variable length argument list?
main() { char string[]="Hello World"; display(string); } void display(char *string) { printf("%s",string); }
Is the following code legal? void main() { typedef struct a aType; aType someVariable; struct a { int x; aType *b; }; }
main() { char str1[] = {‘s’,’o’,’m’,’e’}; char str2[] = {‘s’,’o’,’m’,’e’,’\0’}; while (strcmp(str1,str2)) printf(“Strings are not equal\n”); }
#define prod(a,b) a*b main() { int x=3,y=4; printf("%d",prod(x+2,y-1)); }