Вы находитесь на странице: 1из 60

C Fundamentals

Data Types, Constants & Variables, Playing with scanf function, Operators &
Expressions

[Q001] What will be the output of the following program :


int main()
{
printf("%d",sizeof(integer));
return(0);
}

(a)2 (b)Compile-Time Error (c)4 (d)None of these

[Q002] What will be the output of the following program :


int main()
{
char str[]="C For Swimmers";
printf("%d",sizeof str);
return(0);
}

(a)14 (b)Compile-Time Error (c)15 (d)None of these

[Q003] What will be the output of the following program :

int main()
{
char str[]="C For Swimmers";
printf("%d",++(sizeof(str)));
return(0);
}

(a)14 (b)Compile-Time Error (c)15 (d)None of these

[Q004] What will be the output of the following program :


int main()
{
int x=5,y=6,z=2;
z/=y/z==3?y/z:x*y;
printf("%d",z);
return(0);
}

(a)Compile-Time Error (b)2 (c)0 (d)1

[Q005] What will be the output of the following program :

1
int main()
{
int a=500,b=100,c=30,d=40,e=19;
a+=b-=c*=d/=e%=5;
printf("%d %d %d %d %d",a,b,c,d,e);
return(0);
}
(a)500 100 30 40 4 (b)Run-Time Error (c)700 200 300 10 4 (d)300 -200 300 10 4

[Q006] What will be the output of the following program :


int main()
{
int a=500,b=100,c=30,d=40,e=19;
if ((((a > b) ? c : d) >= e) && !((e <= d) ? ((a / 5) == b) : (c == d)))
printf("Success");
else
printf("Failure");
return(0);
}
(a)Success (b)Failure (c)Invalid Statement(s) (d)None of these

[Q007] What will be the output of the following program :


int main()
{
int a=1,b=2,c=3,d=4;
printf("%d",!a?b?!c:!d:a);
return(0);
}
(a)1 (b)2 (c)3 (d)4

[Q008] What will be the output of the following program :


int main()
{
int i=12345,j=-13579,k=-24680;
long ix=123456789;
short sx=-2222;
unsigned ux=5555;
printf("\n%d %d %d %ld %d %u",i,j,k,ix,sx,ux);
printf("\n\n%3d %3d %3d\n%3ld %3d %3u",i,j,k,ix,sx,ux);
printf("\n\n%8d %8d %8d\n%15ld %8d %8u",i,j,k,ix,sx,ux);
printf("\n\n%-8d %-8d\n%-8d %-15ld\n%-8d %-8u",i,j,k,ix,sx,ux);
printf("\n\n%+8d %+8d\n%+8d %+15ld\n%+8d %8u",i,j,k,ix,sx,ux);
printf("\n\n%08d %08d\n%08d %015ld\n%08d %08u",i,j,k,ix,sx,ux);
return(0);
}

[Q009] What will be the output of the following program :


int main()
{
int i=12345,j=0xabcd9,k=077777;
printf("%d %x %o",i,j,k);

2
printf("\n%3d %3x %3o",i,j,k);
printf("\n%8d %8x %8o"i,j,k);
printf("\n%-8d %-8x %-8o",i,j,k);
printf("\n%+8d %+8x %+8o",i,j,k);
printf("\n%08d %#8x %#8o",i,j,k);
return(0);
}

[Q010] What will be the output of the following program :


int main()
{
char c1='A', c2='B', c3='C';
printf("%c %c %c",c1,c2,c3);A B C
printf("\n%c%c%c",c1,c2,c3);ABC
printf("\n%3c %3c %3c",c1,c2,c3); A B C
printf("\n%3c%3c%3c",c1,c2,c3); A B C
printf("\nc1=%c c2=%c c3=%c",c1,c2,c3);
return(0);
}

[Q011] What will be the output of the following program :


int main()
{
float a=2.5, b=0.0005, c=3000.;
printf("%f %f %f",a,b,c);
printf("\n%3f %3f %3f",a,b,c);
printf("\n%8f %8f %8f",a,b,c);
printf("\n%8.4f %8.4f %8.4f",a,b,c);
printf("\n%8.3f %8.3f %8.3f",a,b,c);
printf("\n%e %e %e",a,b,c);
printf("\n%3e %3e %3e",a,b,c);
printf("\n%12e %12e %12e",a,b,c);
printf("\n%8.2e %8.2e %8.2e",a,b,c);
printf("\n%-8f %-8f %-8f",a,b,c);
printf("\n%+8f %+8f %+8f",a,b,c);
printf("\n%08f %08f %08f",a,b,c);
printf("\n%#8f %#8f %#8f",a,b,c);
printf("\n%g %g %g",a,b,c);
printf("\n%#g %#g %#g"a,b,c);
return(0);
}

[Q012] What will be the output of the following program :


int main()
{
char str[]="C For Swimmers";
printf("%s",str); C FOR SWIMMERS
printf("\n%.5s",str);C FOR
printf("\n%8.*s",5,str); C FOR
printf("\n%-10s %.1s",str+6,str);SWIMMERS C
return(0);
}
3
[Q013] What will be the output of the following program [NOTE : 3 values entered by the user
are:100 200 300] :

int main()
{
int a=1,b=2,c=3;
scanf("%d %*d %d",&a,&b,&c);
printf("a=%d b=%d c=%d",a,b,c);
return(0);
}

(a)1 2 3 (b)100 200 300 (c)100 200 3 (d)100 300 3

[Q014] What will be the output of the following program [NOTE : THE USER INPUT IS:Dear Friends,
What is the output?] :
int main()
{
char line[80]; // Max. length=80 Chars
scanf("%[^,]s",line);
printf("\n%s",line);
return(0);
}

(a)Compile-Time Error (b)Dear Friends (c)What is the output? (d)None of these

[Q015] What will be the output of the following program [NOTE : THE USER INPUT IS :A B C] :
int main()
{
char a,b,c;
scanf("%c%c%c",&a,&b,&c);
printf("a=%c b=%c c=%c",a,b,c);
return(0);
}
(a)a=A b=B c=C (b)a=A b= c=B (c)a=A b= c=C (d)None of these

[Q016] What will be the output of the following program [NOTE : THE USER INPUT IS:5 5.75] :
int main()
{
int i=1;
float f=2.25;
scanf("%d a %f",&i,&f);
printf("%d %.2f",i,f);
return(0);
}

(a)Printing...97 (b)97 (c)Compile-Time Error (d)a

[Q017] What will be the output of the following program [NOTE : THE USER INPUT IS :ABC DEF
GHI] :
int main()
{
char a,b,c;
scanf("%c %c %c",&a,&b,&c);

4
printf("a=%c b=%c c=%c",a,b,c);
return(0);
}

(a)a=ABC b=DEF c=GHI (b)a=A b=B c=C (c)a=A b=D c=G (d)None of these

[Q018] What will be the output of the following program [NOTE : THE USER INPUT IS:CMeansSea
Ocean Vast] :
int main()
{
char a[80],b[80],c[80];
scanf("%1s %5s %3s",a,b,c);
printf("%s %s %s",a,b,c);
return(0);
}

(a)C O V (b)C Means Sea (c)C Ocean Vas (d)None of these

[Q019] What will be the output of the following program [NOTE : THE USER INPUT IS :123456 44
544] :
int main()
{
int a,b,c;
scanf("%1d %2d %3d",&a,&b,&c);
printf("Sum=%d",a+b+c);
return(0);
}

(a)Sum=480 (b)Sum=594 (c)Sum=589 (d)None of these

[Q020] What will be the output of the following program :


int main()
{
char line[80];
scanf("%[^1234567890\n]",line);
return(0);
}

(a)Accepts the string that contains DIGITS only.


(b)Accepts the string that contains DIGITS and NEWLINE characters.
(c)Accepts the string that contains anything other than the DIGITS and NEWLINE
characters.
(d)None of these

INPUT AND OUTPUT STATEMENT

[Q001] What will be the output of the following program :


int main()
{
printf();
return(0);
}

5
(a)Run-Time Error (b)Compile-Time Error (c)No Output (d)None of these

[Q002] What will be the output of the following program :


int main()
{
printf(NULL);
return(0);
}

(a)Run-Time Error (b)Compile-Time Error (c)No Output (d)None of these

[Q003] What will be the output of the following program :


int main()
{
printf("%%",7);
return(0);
}

(a)7 (b)Compile-Time Error (c)% (d)%%

[Q004] What will be the output of the following program :


int main()
{
printf("//",5);
return(0);
}

(a)5 (b)Compile-Time Error (c)/ (d)//

[Q005] What will be the output of the following program :


int main()
{
printf("d%",8);
return(0);
}

(a)8 (b)Compile-Time Error (c)d% (d)None of these

6
[Q006] What will be the output of the following program :
int main()
{
printf("%d"+0,123);
return(0);
}

(a)123 (b)Compile-Time Error (c)No Output (d)None of these

[Q007] What will be the output of the following program :


int main()
{
printf("%d"+1,123);
return(0);
}

(a)123 (b)Compile-Time Error (c)d (d)No Output

[Q008] What will be the output of the following program :


int main()
{
printf("%d",printf("Hi!")+printf("Bye"));
return(0);
}

(a)ByeHi!6 (b)Hi!Bye6 (c)Compile-Time Error (d)None of these

[Q009] What will be the output of the following program :


int main()
{
printf("%d",printf("Hi!")*printf("Bye"));
return(0);
}

(a)ByeHi!6 (b)Hi!Bye9 (c)Hi!Bye (d)None of these

7
[Q010] What will be the output of the following program :
int main()
{
printf("%d",printf("")+printf(""));
return(0);
}

(a)0 (b)No Output (c)Compile-Time Error (d)None of these

[Q011] What will be the output of the following program :


int main()
{
printf("Hi Friends"+3);
return(0);
}

(a)Hi Friends (b)Friends (c)Hi Friends3 (d)None of these

[Q012] What will be the output of the following program :


int main()
{
printf("\/\*\-*\/");
return(0);
}

(a)Run-Time Error (b)\/*-*\/ (c)/*-*/ (d)None of these

[Q013] What will be the output of the following program :


int main()
{
int main=7;
{
printf("%d",main);
return main;
}
printf("Bye");
return(0);
}

(a)Compile-Time Error (b)Run-Time Error (c)7Bye (d)7

8
[Q014] What will be the output of the following program :
int main()
{
main();
return(0);
}

(a)Compile-Time Error (b)Executes ONLY once (c)Infinite Loop (d)None of these

[Q015] What will be the output of the following program :


int main()
{
printf("Work" "Hard");
return(0);
}

(a)Work (b)Hard (c)No Output (d)WorkHard

[Q016] What will be the output of the following program :


int main()
{
char str[]="%d";
int val=25;
printf(str,val);
return(0);
}

(a)Compile-Time Error (b)Run-Time Error (c)25 (d)None of these

[Q017] What will be the output of the following program :


{
int val=10;
printf("%d",val+1,"%d",val--);
return(0);
}

(a)10 (b)11 10 (c)11 9 (d)10 9

9
[Q018] What will be the output of the following program :
#define Compute(x,y,z) (x+y-z)
int main()
{
int x=2,y=3,z=4;
printf("%d",Compute(y,z,(-x+y)) * Compute(z,x,(-y+z))); 6 * 5
return(0);
}

(a)40 (b)30 (c)Compile-Time Error (d)None of these

[Q019] What will be the output of the following program :


int main()
{
int m=10,n=20;
/* printf("%d",m*n);
return(0);
}

(a)VALID but No Output (b)VALID : Prints 200 (c)Compile-Time Error


(d)None of these

[Q020] What will be the output of the following program :


int main()
{
int val=97;
"Printing..."+printf("%c",val);
return(0);
}

(a)Printing...97 (b)97 (c)Compile-Time Error (d)a

[Q021] What will be the output of the following program :


int main()
{
char str[]="Test";
if ((printf("%s",str)) == 4)
printf("Success");
else
printf("Failure");
return(0);
}

(a)TestFailure (b)Test Success (c)Compile-Time Error (d)Test

10
[[Q022] What will be the output of the following program :
int main()
{
int val=5;
printf("%*d",val,val);
return(0);
}
(a)bbbbb5 (where b means blankspace) (b)5 (c)Compile-Time Error
(d)None of these

[[Q023] What will be the output of the following program :


int main()
{
int val=5;
printf("%d5",val);
return(0);
}

(a)Compile-Time Error (b)5 (c)55 (d)bbbbb5 (where b means blankspace)

Decision-making, Bit-wise operations, Branching and Looping

[Q001] What will be the output of the following program :


int main()
{
printf("Hi!");
if (0 || -1)
printf("Bye");
return(0);
}

(a)No Output (b)Hi! (c)Bye (d)Hi!Bye

[Q002] What will be the output of the following program :


int main()
{
printf("Hi!");
if !(0)

11
printf("Bye");
return(0);
}

(a)Compile-Time error (b)Hi! (c)Bye (d)Hi!Bye

[Q003] What will be the output of the following program :


int main()
{
if (sizeof(int) && sizeof(float) && sizeof(float)/2-sizeof(int))
printf("Testing");
printf("OK");
return(0);
}

(a)No Output (b)OK (c)Testing (d)TestingOK

[Q004] What will be the output of the following program :

int main()
{
int a=1,b=2,c=3,d=4,e;
if (e=(a & b | c ^ d))
printf("%d",e);
return(0);
}

(a)0 (b)7 (c)3 (d)No Output exclusive or if any input is one, it is one else zero

[Q005] What will be the output of the following program :


int main()
{
unsigned val=0xffff;
if (~val) // bitwise complement

12
printf("%d",val);
printf("%d",~val);
return(0);
}

(a)Compile-Time error (b)-1 (c)0 (d)-1 0

[Q006] What will be the output of the following program :

int main()
{
unsigned a=0xe75f,b=0x0EF4,c;
c=(a|b);
if ((c > a) && (c > b))
printf("%x",c);
return(0);
}

(a)No Output (b)0xe75f (c)0xefff (d)None of these

[Q007] What will be the output of the following program :

int main()
{
unsigned val=0xabcd;
if (val>>16 | val<<16)
{
printf("Success");
return;
}
printf("Failure");
return(0);
}

(a)No Output (b)Success (c)Failure (d)SuccessFailure

13
[Q008] What will be the output of the following program :

int main()
{
unsigned x=0xf880,y=5,z;
z=x<<y;
printf("%#x %#x",z,x>>y-1);
return(0);
}

(a)1000 f87 (b)8800 0xf88 (c)1000 f88 (d)0x1000 0xf88

[Q009] What will be the output of the following program :


int main()
{
register int a=5;
int *b=&a;
printf("%d %d",a,*b);
return(0);
}

(a)Compile-Time error (b)Run-Time error (c)5 5 (d)Unpredictable

[Q010] What will be the output of the following program :

auto int b=10;


int main()
{
auto int a=5;
printf("%d",a);
return(0);

14
}

(a)Compile-Time error (b)Run-Time error (c)5 (d)Unpredictable

[Q011] What will be the output of the following program :


int main()
{
int a=1;
if (a == 2);
printf("C Program");
return(0);
}

(a)No Output (b)C Program (c)Compile-Time Error

[Q012] What will be the output of the following program :


int main()
{
int i=1;
for (; i<4; i++);
printf("%d\n",i);
return(0);
}

(a)No Output (b) 1 2 3 (c)4 (d)None of these

[Q013] What will be the output of the following program :

int main()
{
int a,b;
for (a=0; a<10; a++);
for (b=25; b>9; b-=3);
15
printf("%d %d",a,b);
return(0);
}

(a)Compile-Time error (b)10 9 (c)10 7 (d)None of these

[Q014] What will be the output of the following program :

int main()
{
int i;
for (i=-10; !i; i++);
printf("%d",-i);
return(0);
}

(a)0 (b)Compile-Time Error (c)10 (d)No Output

[Q015] What will be the output of the following program :

int main()
{
int i=5;
do;
printf("%d",i--);
while (i>0);
return(0);
}

(a)5 (b)54321 (c)Compile-Time Error (d)None of these

[Q016] What will be the output of the following program :

int main()

16
{
int i;
for (i=2,i+=2; i<=9; i+=2)
printf("%d",i);
return(0);
}

(a)Compile-Time error (b)2468 (c)468 (d)None of these

[Q017] What will be the output of the following program :

int main()
{
int i=3;
for (i--; i<7; i=7)
printf("%d",i++);
return(0);
}
(a)No Output
(b)3456
(c)23456
(d)None of these

[Q018] What will be the output of the following program :

int main()
{
int i;
for (i=5; --i;)
printf("%d",i);
return(0);
}
(a)No Output
(b)54321
(c)4321
(d)None of these

17
[Q019] What will be the output of the following program :
int main()
{
int choice=3;
switch(choice)
{
default:
printf("Default");

case 1:
printf("Choice1");
break;

case 2:
printf("Choice2");
break;
}
return(0);
}

(a)No Output (b)Default (c)DefaultChoice1 (d)None of these

[Q020] What will be the output of the following program :

int main()
{
static int choice;
switch(--choice,choice-1,choice-1,choice+=2)
{
case 1:
printf("Choice1");
break;

case 2:
printf("Choice2");

18
break;

default:
printf("Default");
}
return(0);
}

(a)Choice1 (b)Choice2 (c)Default (d)None of these

[Q021] What will be the output of the following program :

int main()
{
for (;printf(""););
return(0);
}
(a)Compile-Time error (b)Executes ONLY once (c)Executes INFINITELY
(d)None of these

[Q022] What will be the output of the following program :


int main()
{
int i;
for (;(i=4)?(i-4):i++;)
printf("%d",i);
return(0);
}

(a)Compile-Time error (b)4 (c)Infinite Loop (d)No Output

Functions

[Q001] The following code is not well-written. What does the program do ?
void main()
{

19
int a=1,b=2;
printf("%d",add(a,b));
}
int add(int a,int b)
{
return (a+b);
}
(a)Run-Time Error (b)Compile-Time Error (c)3 (d)None of these
Ans. (b)

[Q003] What will be the output of the following program :

int add(int a,int b)


{
int c=a+b;
return;
}
void main()
{
int a=10,b=20;
printf("%d %d %d",a,b,add(a,b));
}
(a)10 20 0 (b)Compile-Time Error (c)10 20 30 (d)None of these
Ans. (c)

[Q004] What will be the output of the following program :

void main()
{
20
int add(int,int);
int a=7,b=13;
printf("%d",add(add(a,b),add(a,b)));
}
int add(a,b)
int a,b;
{
return (a+b);
}
(a)Compile-Time error (b)20 (c)40 (d)None of these
Ans. (c)

[Q005] What will be the output of the following program :


int add(a,b)
{
int c=a+b;
return c;
}
void main()
{
int a=10,b=20;
printf("%d",add(a,b));
}
(a)30 (b)Compile-Time Error (c)0 (d)None of these
Ans. (a)

[Q006] What will be the output of the following program :


int funct2(int b)
{
if (b == 0)
return b;
else
funct1(b--);
}
int funct1(int a)
{

21
if (a == 0)
return a;
else
funct2(a--);
}
void main()
{
int a=7;
printf("%d",funct1(a));
}
(a)0 (b)Compile-Time Error (c)Infinite Loop (d)7
Ans. (c)

[Q007] What will be the output of the following program :


int funct2(int b)
{
if (b == 0)
return b;
else
funct1(--b);
}
int funct1(int a)
{
if (a == 0)
return a;
else
funct2(--a);
}
void main()
{
int a=7;
printf("%d",funct1(a));
}
(a)0 (b)Compile-Time Error (c)Infinite Loop (d)7
Ans. (a)

22
[Q008] What will be the output of the following program :
int funct1(int a)
{{;}{{;}return a;}}
void main()
{
int a=17;
printf("%d",funct1(a));
}
(a)0 (b)Compile-Time Error (c)17 (d)None of these
Ans. (c)

[Q009] What will be the output of the following program :


int funct1(int a)
{
if (a)
return funct1(--a)+a;
else
return 0;
}
void main()
{
int a=7;
printf("%d",funct1(a));
}
(a)7 (b)21 (c)28 (d)None of these
Ans. (c)

[Q010] What will be the output of the following program :


int compute(int a,int b)
int c;
{
c=a+b;
return c;
}
void main()
{

23
int a=7,b=9;
printf("%d",compute(a,b));
}
(a)Compile-Time Error (b)16 (c)None of these
Ans. (a)

[Q011]What will be the output of the following program :


int a=10;
void compute(int a)
{
a=a;
}
void main()
{
int a=100;
printf("%d ",a);
compute(a);
printf("%d",a);
}
(a)10 10 (b)Compile-Time Error (c)100 100 (d)100 10
Ans. (c)

[Q012] What will be the output of the following program :


int funct(char ch)
{
ch=ch+1;
return ch;
}
void main()
{
int a=127;
printf("%d %d",a,funct(a));
}
(((a)Compile-Time Error (b)127 128 (c)127 -128 (d)None of these
Ans. (c)

24
[Q013] What will be the output of the following program :
char funct(int val)
{
char ch=val;
return ch;
}
void main()
{
float a=256.25;
printf("%d",funct(a));
}
(a)0 (b)256.25 (c)256 (d)None of these
Ans. (a)

[Q014]What will be the output of the following program :


auto int a;
void changeval(int x)
{
a=x;
}
void main()
{
a=15;
printf("%d",a);
changeval(75);
printf("%d",a);
}
(a)Compile-Time Error (b)15 75 (c)15 15 (d)None of these
Ans. (a)

[Q015]What will be the output of the following program :


int val;
static int funct()
{
25
return val*val;
}
void main()
{
val=5;
funct();
val++;
printf("%d",funct());
}

(a)Compile-Time Error (b)25 (c)36 (d)None of these


Ans. (c)

[Q016] What will be the output of the following program :


static int funct(int val)
{
static int sum;
sum+=val;
return sum;
}
void main()
{
int i,n=9;
for (i=1; i<n--; i++)
funct(i*2);
printf("%d",funct(0));
}
(a)20 (b)0 (c)30 (d)None of these
Ans. (a)

[Q017]What will be the output of the following program :


void print(int a[],...)
{
while (*a != -1)
printf("%d",*a++);
}

26
void main()
{
int a[]={1,2,3,4,5,-1};
print(a,5,6,7,8,9,-1);
}
(a)Compile-Time Error (b)Run-Time Error (c)12345 (d)56789
Ans. (c)

[Q018] What will be the output of the following program :


void print(int *);
void print(int *);
void main()
{
int x=100;
print(&x);
}
void print(int *a)
{
printf("%d",*a);
}
(a)Compile-Time Error (b)Run-Time Error (c)100 (d)None of these
Ans. (c)

[Q019] What will be the output of the following program :


void main()
{
void funct1(void);
void funct2(void);
clrscr();
funct1();
}
void funct1(void)
{
printf("Ocean of ");
funct2();
}

27
void funct2(void)
{
printf("Knowledge");
}
(a)Compile-Time Error (b)Run-Time Error (c)Ocean of Knowledge (d)None of these
Ans. (a)

[Q020]
What will be the output of the following program :
static int count=1;
void funct3(void)
{
printf("%d",++count);
}
void funct2(void)
{
printf("%d",count);
funct3();
}
void funct1(void)
{
printf("Counting...%d",count++);
funct2();
}
void Main()
{
funct1();
}
(a)Compile-Time Error (b)Counting...123 (c)Counting...111 (d)Counting...112
Ans. (a) Since main() is different from Main() i.e. linker error

[Q001] Several declarations involving pointers are shown below. Pick the correct solution.
int *ptr;
(a)ptr is a integer variable
(b)ptr is a pointer to an integer quantity
(c)Invalid statement
(d)None of these

28
[Q002] Several declarations involving pointers are shown below. Pick the correct solution.
int *ptr[10];
(a)ptr is a pointer to an integer quantity
(b)ptr is a pointer to a 10-element integer array
(c)ptr is a 10-element array of pointers to integer quantities
(d)None of these

[Q003] Several declarations involving pointers are shown below. Pick the correct solution.
int (*ptr)[10];
(a)ptr is a pointer to an integer quantity
(b)ptr is a pointer to a 10-element integer array
(c)ptr is a 10-element array of pointers to integer quantities
(d)None of these

[Q004] Several declarations involving pointers are shown below. Pick the correct solution.
int *ptr(void);
(a)ptr is a pointer to an integer
(b)ptr is a function that returns a pointer to an integer quantity
(c)ptr is a function pointer that returns integer quantity
(d)None of these

[Q005] Several declarations involving pointers are shown below. Pick the correct solution.
int ptr(int *a);
(a)Invalid statement
(b)ptr is a function that accepts an argument which is a pointer to a integer returns an integer
quantity
(c)ptr is a function pointer
(d)None of these

29
[Q006] Several declarations involving pointers are shown below. Pick the correct
solution.
int *ptr(int *a);
(a)Invalid statement
(b)ptr is a function pointer that accepts an argument which is a pointer to a integer returns
an integer quantity
(c)ptr is a function that accepts an argument which is a pointer to a integer returns a pointer to an
integer quantity
(d)None of these

[Q007] Several declarations involving pointers are shown below. Pick the correct solution.
int (*ptr)(char *a);
(a)Invalid statement
(b)ptr is a pointer to a function that accepts an argument which is a pointer to a character
returns an integer quantity
(c)ptr is a function that accepts an argument which is a pointer to a character returns a pointer to an
integer quantity
(d)None of these

[Q008] Several declarations involving pointers are shown below. Pick the correct solution.

int (*ptr(int *b))[5];


(a)Invalid statement
(b)ptr is a pointer to a function that accepts pointer to an integer returns a 5-element
integer array
(c)ptr is a function that accepts an argument which is a pointer to a integer returns a pointer to a 5-
element integer array
(d)None of these

[Q009] Several declarations involving pointers are shown below. Pick the correct solution.
char ptr(int (*a)[]);
(a)Invalid statement
(b)ptr is a function that accepts an argument which is a pointer to a integer array returns
an character quantity
(c)ptr is a function that accepts an argument which is an array of pointers to integers returns an
character quantity
30
(d)None of these

[Q010] Several declarations involving pointers are shown below. Pick the correct solution.
char ptr(int *a[]);
(a)Invalid statement
(b)ptr is a function that accepts an argument which is a pointer to a integer array returns
an character quantity
(c)ptr is a function that accepts an argument which is an array of pointers to integers returns an
character quantity
(d)None of these

[Q011] Several declarations involving pointers are shown below. Pick the correct solution.
int *ptr(char a[]);
(a)ptr is a function pointer
(b)ptr is a function that accepts an argument which is a character array returns an integer
(c)ptr is a function that accepts an argument which is a character array returns a pointer
to an integer quantity
(d)None of these

[Q012] Several declarations involving pointers are shown below. Pick the correct solution.
int *ptr(char *a[]);
(a)ptr is a function pointer
(b)ptr is a function that accepts an argument which is a pointer to a character array
returns a pointer to an integer quantity
(c)ptr is a function that accepts an argument which is a array of pointers to characters
returns a pointer to an integer quantity
(d)None of these

[Q013] Several declarations involving pointers are shown below. Pick the correct solution.
int (*ptr)(char (*a)[]);

31
(a)ptr is a function that accepts an argument which is a pointer to a character array
returns a pointer to an integer quantity
(b)ptr is a pointer to a function that accepts an argument which is a pointer to a character
array returns an integer quantity
(c)ptr is a pointer to a function that accepts an argument which is a array of pointers to
characters returns an integer quantity
(d)None of these

[Q014] Several declarations involving pointers are shown below. Pick the correct solution.
int *(*ptr)(char (*a)[]);
(a)ptr is a function that accepts an argument which is a pointer to a character array
returns a pointer to an integer quantity
(b)ptr is a pointer to a function that accepts an argument which is a pointer to a character
array returns a pointer to an integer quantity
(c)ptr is a pointer to a function that accepts an argument which is a array of pointers to
characters returns a pointer to an integer quantity
(d)None of these

[Q015] Several declarations involving pointers are shown below. Pick the correct solution.
int *(*ptr)(char (*a)[]);
(a)ptr is a function that accepts an argument which is a pointer to a character array
returns a pointer to an integer quantity
(b)ptr is a pointer to a function that accepts an argument which is a pointer to a character
array returns a pointer to an integer quantity
(c)ptr is a pointer to a function that accepts an argument which is an array of pointers to
characters returns a pointer to an integer quantity
(d)None of these

[Q016] Several declarations involving pointers are shown below. Pick the correct solution.
int (*ptr[10])(void);
(a)Invalid statement
(b)ptr is a function that returns an integer quantity
(c)ptr is a 10-element array of pointers to functions. Each function returns an integer
quantity.

32
(d)ptr is pointer to a function that returns a pointer to a 10-element integers

[Q017] Several declarations involving pointers are shown below. Pick the correct solution.
int (*ptr[10])(float a);
(a)Invalid statement
(b)ptr is a function that returns an integer quantity
(c)ptr is a 10-element array of pointers to functions. Each function accepts an argument
which is a float and returns an integer quantity.
(d)ptr is pointer to a function that accepts an argument which is a float and returns a
pointer to a 10-element integers

[Q018] Several declarations involving pointers are shown below. Pick the correct solution.
int *(*ptr[10])(float a);
(a)Invalid statement
(b)ptr is a function that returns an integer quantity
(c)ptr is a 10-element array of pointers to functions. Each function accepts an argument
which is a float and returns an integer quantity.
(d)ptr is a 10-element array of pointers to functions. Each function accepts an argument
which is a float and returns a pointer to an integer quantity.

[Q019] Several declarations involving pointers are shown below. Pick the correct solution.
int *(*ptr[10])(float *a);
(a)Invalid statement
(b)ptr is a function that returns an integer quantity
(c)ptr is a 10-element array of pointers to functions. Each function accepts an argument
which is a pointer to a float and returns an integer quantity.
(d)ptr is a 10-element array of pointers to functions. Each function accepts an argument
which is a pointer to a float and returns a pointer to an integer quantity.

[Q020] Several declarations involving pointers are shown below. Pick the correct solution.
int *ptr(char (*a)[]);

33
(a)ptr is a function pointer
(b)ptr is a function that accepts an argument which is a pointer to a character array
returns a pointer to an integer quantity
(c)ptr is a function that accepts an argument which is a array of pointers to characters
returns a pointer to an integer quantity

[Q002]

(c)ptr is a 10-element array of pointers to integer quantities

[Q003]

(b)ptr is a pointer to a 10-element integer array

[Q004]

(b)ptr is a function that returns a pointer to an integer quantity

[Q005]

(b)ptr is a function that accepts an argument which is a pointer to a integer returns an


integer quantity

[Q006]

34
(c)ptr is a function that accepts an argument which is a pointer to a integer returns a
pointer to an integer quantity

[Q007]

(b)ptr is a pointer to a function that accepts an argument which is a pointer to a character


returns an integer quantity

[Q008]

(c)ptr is a function that accepts an argument which is a pointer to a integer returns a


pointer to a 5-element integer array

[Q009]

(b)ptr is a function that accepts an argument which is a pointer to a integer array returns
an character quantity

[Q010]

(c)ptr is a function that accepts an argument which is an array of pointers to integers


returns an character quantity

[Q011]

35
(c)ptr is a function that accepts an argument which is a character array returns a pointer
to an integer quantity

[Q012]

(c)ptr is a function that accepts an argument which is a array of pointers to characters


returns a pointer to an integer quantity

[Q013]

(b)ptr is a pointer to a function that accepts an argument which is a pointer to a character


array returns an integer quantity

[Q014]

(b)ptr is a pointer to a function that accepts an argument which is a pointer to a character


array returns a pointer to an integer quantity

[Q015]

(c)ptr is a pointer to a function that accepts an argument which is an array of pointers to


characters returns a pointer to an integer quantity

[Q016]

36
(c)ptr is a 10-element array of pointers to functions. Each function returns an integer
quantity

[Q017]

(c)ptr is a 10-element array of pointers to functions. Each function accepts an argument


which is a float and returns an integer quantity

[Q018]

(d)ptr is a 10-element array of pointers to functions. Each function accepts an argument


which is a float and returns a pointer to an integer quantity

[Q019]

(d)ptr is a 10-element array of pointers to functions. Each function accepts an argument


which is a pointer to a float and returns a pointer to an integer quantity

[Q020]

(b)ptr is a function that accepts an argument which is a pointer to a character array


returns a pointer to an integer quantity
[Q001] What will be the output of the following program :
int main()
{
int val=1234;
int* ptr=&val;
printf("%d %d",++val,*ptr);
return(0);

37
}

(a)1234 1234 (b)1235 1235 (c)1234 1235 (d)1235 1234

[Q002] What will be the output of the following program :


int main()
{
int val=1234;
int* ptr=&val;
printf("%d %d",val,*ptr++);
return(0);
}

(a)1234 1234 (b)1235 1235 (c)1234 1235 (d)1235 1234

[Q003] What will be the output of the following program :


int main()
{
int val=1234;
int *ptr=&val;
printf("%d %d",val,++*ptr);
return(0);
}

(a)1234 1234 (b)1235 1235 (c)1234 1235 (d)1235 1234

[Q004] What will be the output of the following program :


int main()
{
int val=1234;
int *ptr=&val;
printf("%d %d",val,(*ptr)++);
return(0);
38
}

(a)1234 1234 (b)1235 1235 (c)1234 1235 (d)1235 1234

[Q005] What will be the output of the following program :

int main()
{
int val=1234;
int *ptr=&val;
printf("%d %d",++val,(*(int *)ptr)--);
return(0);
}

(a)1234 1233 (b)1235 1234 (c)1234 1234 (d)None of these

[Q006] What will be the output of the following program :


int main()
{
int a=555,*ptr=&a,b=*ptr;
printf("%d %d %d",++a,--b,*ptr++);
return(0);
}

(a)Compile-Time Error (b)555 554 555 (c)556 554 555 (d)557 554 555

[Q007] What will be the output of the following program :


int main()
{
int a=555,b=*ptr,*ptr=&a;
printf("%d %d %d",++a,--b,*ptr++);
return(0);
}
39
(a)Compile-Time Error (b)555 554 555 (c)556 554 555 (d)557 554 555

[Q008] What will be the output of the following program :


int main()
{
int a=555,*ptr=&a,b=*ptr;
printf("%d %d %d",a,--*&b,*ptr++);
return(0);
}

(a)Compile-Time Error (b)555 554 555 (c)556 554 555 (d)557 554 555

[Q009] What will be the output of the following program :


int main()
{
int a=555,*ptr=&a,b=*ptr=777;
printf("%d %d",--*&b,*(int *)&b);
return(0);
}

(a)Compile-Time Error (b)776 777 (c)554 555 (d)None of these

[Q010] What will be the output of the following program :

int main()
{
int a=5u,*b,**c,***d,****e;
b=&a;
c=&b;
d=&c;
e=&d;
printf("%u %u %u %u",*b-5,**c-11,***d-6,65535+****e);
return(0);

40
}

(a)Compile-Time Error (b)0 65530 65535 4


(c)0 65530 65535 65539 (d)0 -6 -1 -2

[Q011] What will be the output of the following program :

int main()
{
float val=5.75;
int *ptr=&val;
printf("%.2f %.2f",*(float *)ptr,val);
return(0);
}

(a)Compile-Time Error (b)5.75 5.75 (c)5.00 5.75 (d)None of these

[Q012] What will be the output of the following program :


int main()
{
int val=50;
const int *ptr1=&val;
int const *ptr2=ptr1;
printf("%d %d %d",++val,*ptr1,*ptr2);
*(int *)ptr1=98;
printf("\n%d %d %d",++val,*ptr1,*ptr2);
return(0);
}
(a)Compile-Time Error
(b)51 50 50
99 98 98
(c)Run-Time Error
(d)None of these

41
[Q013] What will be the output of the following program :
int main()
{
int val=77;
const int *ptr1=&val;
int const *ptr2=ptr1;
printf("%d %d %d",--val,(*ptr1)++,*ptr2);
return(0);
}

(a)Compile-Time Error (b)77 78 77 (c)76 77 77 (d)77 77 77

[Q014] What will be the output of the following program :


int main()
{
int a=50,b=60;
int* const ptr1=&a;
printf("%d %d",--a,(*ptr1)++);
ptr1=&b;
printf("\n%d %d",++b,(*ptr1)++);
return(0);
}
(a)Compile-Time Error
(b)49 50
61 60
(c)50 50
62 60
(d)None of these

[Q015] What will be the output of the following program :


int main()
{
int a=50;
const int* const ptr=&a;
printf("%d %d",*ptr++,(*ptr)++);
return(0);
}
42
(a)Compile-Time Error (b)51 51 (c)51 50 (d)None of these

[Q016] What will be the output of the following program :


int main()
{
int val=77;
const int const *ptr=&val;
printf("%d",*ptr);
return(0);
}

(a)Compile-Time Error (b)Run-Time Error (c)77 (d)None of these

[Q017] What will be the output of the following program :


int main()
{
int a[]={1,2,3,4,5,6};
int *ptr=a+2;
printf("%d %d",--*ptr+1,1+*--ptr);
return(0);
}

(a)Compile-Time Error (b)1 2 (c)2 3 (d)1 3

[Q018] What will be the output of the following program :

int main()
{
int a[]={1,2,3,4,5,6};
int *ptr=a+2;
printf("%d %d",*++a,--*ptr);
return(0);
}

43
(a)Compile-Time Error (b)2 2 (c)3 2 (d)4 2

[Q019] What will be the output of the following program :


int main()
{
int matrix[2][3]={{1,2,3},{4,5,6}};
printf("%d %d %d\n",*(*(matrix)),*(*(matrix+1)+2),*(*matrix+1));
printf("%d %d %d",*(matrix[0]+2),*(matrix[1]+1),*(*(matrix+1)));
return(0);
}
(a)Compile-Time Error
(b)1 5 2
634
(c)1 6 2
354
(d)1 6 2
345

[Q020] What will be the output of the following program :


int main()
{
int (*a)[5];
printf("%d %d",sizeof(*a),sizeof(a));
return(0);
}
(a)Compile-Time Error
(b)2 5
(c)10 4
(d)None of these

[Q001] What will be the output of the following program :


struct {
int i;
float f;
}var;
int main()
44
{
var.i=5;
var.f=9.76723;
printf("%d %.2f",var.i,var.f);
return(0);
}

(a)Compile-Time Error (b)5 9.76723 (c)5 9.76 (d)5 9.77

[Q002] What will be the output of the following program :


int main()
{
int val=1234;
int* ptr=&val;
printf("%d %d",val,*ptr++);
return(0);
}

(a)Compile-Time Error (b)5 9.76723 (c)5 9.76 (d)5 9.77

[Q003] What will be the output of the following program :


struct values {
int i;
float f;
};
int main()
{
struct values var={555,67.05501};
printf("%2d %.2f",var.i,var.f);
return(0);
}

(a)1234 1234 (b)1235 1235 (c)1234 1235 (d)1235 1234

45
[Q004] What will be the output of the following program :
typedef struct {
int i;
float f;
}values;
int main()
{
static values var={555,67.05501};
printf("%2d %.2f",var.i,var.f);
return(0);
}

(a)Compile-Time Error (b)55 67.05 (c)555 67.06 (d)555 67.05

[Q005] What will be the output of the following program :

struct my_struct {
int i=7;
float f=999.99;
}var;
int main()
{
var.i=5;
printf("%d %.2f",var.i,var.f);
return(0);
}

(a)Compile-Time Error (b)7 999.99 (c)5 999.99 (d)None of these

[Q006] What will be the output of the following program :


struct first {
int a;
float b;
}s1={32760,12345.12345};
typedef struct {
char a;

46
int b;
}second;
struct my_struct {
float a;
unsigned int b;
};
typedef struct my_struct third;
int main()
{
static second s2={'A',- -4};
third s3;
s3.a=~(s1.a-32760);
s3.b=-++s2.b;
printf("%d %.2f\n%c %d\n%.2f %u",(s1.a)--,s1.b+0.005,s2.a+32,s2.b,++(s3.a),--
s3.b);
return(0);
}
(a)Compile-Time Error (b)32760 12345.12
A4
1 -5
(c)32760 12345.13
a -5
0.00 65531
(d)32760 12345.13
a5
0.00 65530

[Q007] What will be the output of the following program :


struct {
int i,val[25];
}var={1,2,3,4,5,6,7,8,9},*vptr=&var;
int main()
{
printf("%d %d %d\n",var.i,vptr->i,(*vptr).i);
printf("%d %d %d %d %d %d",var.val[4],*(var.val+4),vptr->val[4],*(vptr-
>val+4),(*vptr).val[4],*((*vptr).val+4));
return(0);
}

47
(a)Compile-Time Error (b)1 1 1
666666
(c)1 1 1
555555
(d)None of these

[Q008] What will be the output of the following program :


typedef struct {
int i;
float f;
}temp;
void alter(temp *ptr,int x,float y)
{
ptr->i=x;
ptr->f=y;
}
int main()
{
temp a={111,777.007};
printf("%d %.2f\n",a.i,a.f);
alter(&a,222,666.006);
printf("%d %.2f",a.i,a.f);
return(0);
}
(a)Compile-Time error
(b)111 777.007
222 666.006
(c)111 777.01
222 666.01
(d)None of these

[Q009] What will be the output of the following program :


typedef struct {
int i;
float f;
}temp;
temp alter(temp tmp,int x,float y)

48
{
tmp.i=x;
tmp.f=y;
return tmp;
}
int main()
{
temp a={111,777.007};
printf("%d %.3f\n",a.i,a.f);
a=alter(a,222,666.006);
printf("%d %.3f",a.i,a.f);
return(0);
}
(a)Compile-Time error
(b)111 777.007
222 666.006
(c)111 777.01
222 666.01
(d)None of these

[Q010] What will be the output of the following program :


typedef struct {
int i;
float f;
}temp;
temp alter(temp *ptr,int x,float y)
{
temp tmp=*ptr;
printf("%d %.2f\n",tmp.i,tmp.f);
tmp.i=x;
tmp.f=y;
return tmp;
}
int main()
{
temp a={65535,777.777};
a=alter(&a,-1,666.666);
printf("%d %.2f",a.i,a.f);

49
return(0);
}
(a)Compile-Time error
(b)65535 777.777
-1 666.666
(c)65535 777.78
-1 666.67
(d)-1 777.78
-1 666.67

[Q011] What will be the output of the following program :


struct my_struct1 {
int arr[2][2];
};
typedef struct my_struct1 record;
struct my_struct2 {
record temp;
}list[2]={1,2,3,4,5,6,7,8};
int main()
{
int i,j,k;
for (i=1; i>=0; i--)
for (j=0; j<2; j++)
for (k=1; k>=0; k--)
printf("%d",list[i].temp.arr[j][k]);
return(0);
}
(a)Compile-Time Error
(b)Run-Time Error
(c)65872143
(d)56781243

[Q012] What will be the output of the following program :


struct my_struct {
int i;
unsigned int j;
};
50
int main()
{
struct my_struct temp1={-32769,-1},temp2;
temp2=temp1;
printf("%d %u",temp2.i,temp2.j);
return(0);
}
(a)32767 -1
(b)-32769 -1
(c)-32769 65535
(d)32767 65535

[Q013] What will be the output of the following program :


struct names {
char str[25];
struct names *next;
};
typedef struct names slist;
int main()
{
slist *list,*temp;
list=(slist *)malloc(sizeof(slist)); // Dynamic Memory Allocation
strcpy(list->str,"Hai");
list->next=NULL;
temp=(slist *)malloc(sizeof(slist)); // Dynamic Memory Allocation
strcpy(temp->str,"Friends");
temp->next=list;
list=temp;
while (temp != NULL)
{
printf("%s",temp->str);
temp=temp->next;
}
return(0);
}
(a)Compile-Time Error
(b)HaiFriends
(c)FriendsHai
(d)None of these
51
[Q014] What will be the output of the following program :
(i) struct A {
int a;
struct B {
int b;
struct B *next;
}tempB;
struct A *next;
}tempA;

(ii) struct B {
int b;
struct B *next;
};
struct A {
int a;
struct B tempB;
struct A *next;
};

(iii) struct B {
int b;
}tempB;
struct {
int a;
struct B *nextB;
};

(iv) struct B {
int b;
struct B {
int b;
struct B *nextB;
}tempB;
struct B *nextB;
}tempB;

52
(a) (iv) Only
(b) (iii) Only
(c)All of the these
(d)None of these

[Q015] What will be the output of the following program :


union A {
char ch;
int i;
float f;
}tempA;
int main()
{
tempA.ch='A';
tempA.i=777;
tempA.f=12345.12345;
printf("%d",tempA.i);
return(0);
}
(a)Compile-Time Error
(b)12345
(c)Erroneous output
(d)777

[Q016] What will be the output of the following program :


struct A {
int i;
float f;
union B {
char ch;
int j;
}temp;
}temp1;
int main()
{
struct A temp2[5];
printf("%d %d",sizeof temp1,sizeof(temp2));

53
return(0);
}
(a)6 30
(b)8 40
(c)9 45
(d)None of these

[Q017] What will be the output of the following program :


int main()
{
static struct my_struct {
unsigned a:1;
unsigned b:2;
unsigned c:3;
unsigned d:4;
unsigned :6; // Fill out first word
}v={1,2,7,12};
printf("%d %d %d %d",v.a,v.b,v.c,v.d);
printf("\nSize=%d bytes",sizeof v);
return(0);
}
(a)Compile-Time Error
(b)1 2 7 12
Size=2 bytes
(c)1 2 7 12
Size=4 bytes
(d)None of these

[Q018] What are the largest values that can be assigned to each of the bit fields defined in
[Q017] above.

(a)a=0 b=2 c=3 d=4


(b)a=1 b=2 c=7 d=15
(c)a=1 b=3 c=7 d=15
(d)None of these

54
[Q019] What will be the output of the following program :
int main()
{
struct sample {
unsigned a:1;
unsigned b:4;
}v={0,15};
unsigned *vptr=&v.b;
printf("%d %d",v.b,*vptr);
return(0);
}
(a)Compile-Time Error
(b)0 0
(c)15 15
(d)None of these

[Q020] What will be the output of the following program :


int main()
{
static struct my_struct {
unsigned a:1;
int i;
unsigned b:4;
unsigned c:10;
}v={1,10000,15,555};
printf("%d %d %d %d",v.i,v.a,v.b,v.c);
printf("\nSize=%d bytes",sizeof v);
return(0);
}
(a)Compile-Time Error
(b)1 10000 15 555
Size=4 bytes
(c)10000 1 15 555
Size=4 bytes
(d)10000 1 15 555
Size=5 bytes

55
[Q001]

Ans. (d) Though both <struct type name> and <structure variables> are optional, one of
the two must appear. In the above program, <structure variable> i.e. var is used. (2
decimal places or) 2-digit precision of 9.76723 is 9.77

[Q002]

Ans. (d) Both <struct type name> and <structure variables> are optional. Thus the
structure defined in the above program has no use and program executes in the normal
way.

[Q003]

Ans. (c) The members of a structure variable can be assigned initial values in much the
same manner as the elements of an array. The initial values must appear in order in which
they will be assigned to their corresponding strucutre members, enclosed in braces and
separated by commas.

[Q004]

Ans. (c) In the above program, values is the user-defined structure type or the new user-
defined data type. Structure variables can then be defined in terms of the n ew data type.

[Q005]

Ans. (a) C language does not permit the initialization of individual structure members
within the template. The initialization must be done only in the declaration of the actual
variables. The correct way to initialize the values is shown in [Q003] or [Q004].

56
[Q006]

Ans. (d) Illustrating 3 different ways of declaring the structres : first, second and third are
the user-defined structure type. s1, s2 and s3 are structure variables. Also an expression of
the form ++variable.member is equivalent to ++(variable.member), i.e. ++ operator will
apply to the structure member, not the entire structure variable.

[Q007]

Ans. (b) Since value of the member 'i' can be accessed using var.i, vptr->i and
(*vptr).i Similarly 5th value of the member 'val' can be accessed using var.val[4],
*(var.val+4), vptr->val[4], *(vptr->val+4), (*vptr).val[4] and *((*vptr).val+4)

[Q008]

Ans. (c) This program illustrates the transfer of a structure to a function by passing the
structure's address (a pointer) to the function.

[Q009]

Ans. (b) This program illustrates the transfer of a structure to a function by value. Also the
altered structure is now returned directly to the calling portion of the program.

[Q010]

Ans. (d) This program illustrates the transfer of a structure to a function by passing the
structure's address (a pointer) to the function. Also the altered structure is now returned
directly to the calling portion of the program.

57
[Q011]

Ans. (c) This program illustrates the implementation of a nested structure i.e. structure
inside another structure.

[Q012]

Ans. (d) An entire structure variable can be assigned to another structure variable,
provided both variables have the same composition.

[Q013]

Ans. (c) It is sometimes desirable to include within a structure one member i.e. a pointer
to the parent structure type. Such structures are known as Self-Referencial structures.
These structures are very useful in applications that involve linked data structures, such as
lists and trees. [A linked data structure is not confined to some maximum number of
components. Rather, the data structure can expand or contract in size as required.]

[Q014]

Ans. (d) Since all the above structure declarations are valid in C.

[Q015]

Ans. (c) The above program produces erroneous output (which is machine dependent). In
effect, a union creates a storage location that can be used by any one of its members at a
time. When a different member is assigned a new value, the new value supercedes the
previous member's value. [NOTE : The compiler allocates a piece of storage that is large
enough to hold the largest variable type in the union i.e. all members share the same

58
address.]

[Q016]

Ans. (b) Since int (2 bytes) + float (4 bytes) = (6 bytes) + Largest among union is int (2
bytes) is equal to (8 bytes). Also the total number of bytes the array 'temp2' requires :
(8 bytes) * (5 bytes) = (40 bytes).

[Q017]

Ans. (b) The four fields within 'v' require a total of 10 bits and these bits can be
accomodated within the first word(16 bits). Unnamed fields can be used to control the
alignment of bit fields within a word of memory. Such fields provide padding within the
word. [NOTE : Some compilers order bit-fields from righ-to-left (i.e. from lower-order bits
to high- order bits) within a word, whereas other compilers order the fields from left-to-
right (high- order to low-order bits).

[Q018]

Ans. (c)a=1 (1 bit: 0 or 1)


b=3 (2 bits: 00 or 01 or 10 or 11),
c=7 (3 bits: 000 or 001 or 010 or 011 or 100 or 101 or 110 or 111)
d=15 (4 bits: 0000 or 0001 or 0010 or 0011 or 0100 or 0101 or 0110 or 0111 or 1000
or
1001 or 1010 or 1011 or 1100 or 1101 or 1110 or 1111)

[Q019]

Ans. (a) Since we cannot take the address of a bit field variable i.e. Use of pointer to access
the bit fields is prohibited. Also we cannot use 'scanf' function to read values into a bit field
as it requires the address of a bit field variable. Also array of bit-fields are not permitted

59
and a function cannot return a bit field.

[Q020]

Ans. (d) Here the bit field variable 'a' will be in first byte of one word, the variable 'i' will be
in the second word and the bit fields 'b' and 'c' will be in the third word. The variables 'a',
'b' and 'c' would not get packed into the same word. [NOTE: one word=2 bytes]
[Q001] Write a program (W.A.P.) in C to SWAP the contents of 3 variables without using
the temporary (or extra) variables.

60

Вам также может понравиться