Monday, 28 July 2014

#21. Concepts in C -- only through Examples & Explanations

This is a continuation of last post. 

Before seeing the answer try to predict it & then see the explanation.

All the Best!!

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

67) #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);
}

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

69) main()
{
int i=5,j=6,z;
printf("%d",i+++j);
}

70) #include<stdio.h>
main()
{
struct xx
{
int x=3;
char name[]="hello";
};
struct xx *s=malloc(sizeof(struct xx));
printf("%d",s->x);
printf("%s",s->name);
}

========================================================
66.
Answer:
Compiler error
Explanation:
i is a constant. you cannot change the value of constant

67.
Answer:
garbagevalue..1
Explanation:
p=&a[2][2][2] you declare only two 2D arrays. but you are trying to access
the third 2D(which you are not declared) it will print garbage values. *q=***a
starting address of a is assigned integer pointer. now q is pointing to starting
address of a.if you print *q meAnswer:it will print first element of 3D array.

68.
Answer:
hello 5
Explanation:
if you declare i as register compiler will treat it as ordinary integer and it will
take integer value. i value may be stored either in register or in memory.

69.
Answer:
11
Explanation:
the expression i+++j is treated as (i++ + j)

70.
Answer:
Compiler Error
Explanation:
Initialization should not be done for structure members inside the structure
declaration

========================================================
Thanks for coming till this point!!
VSG
SQL DBA


No comments:

Post a Comment