Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
7K views246 pages

Coding Interview Questions For Round 1

Download as docx, pdf, or txt
Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1/ 246

C-apps questions & answers for arrays and pointers

1)

What will be output of the following c program?

#include "stdio.h"

int main()

int _ = 5;

int __ = 10;

int ___;

___ = _ + __;

printf("%i", ___);

return 0;

(A) 5

(B) 10

(C) 15

(D) Compilation Error

Answer : 15

2)

How many times the below loop will get executed?

main()

int i;

for(i=9;i;i=i-2)

printf("\n%d",i);

}
}

(A) 5

(B) 6

(C) Compilation Error

(D) Infinite

Answer : Infinite

3)

main()

int a,b,c;

a=10;

b=20;

c=printf("%d",a)+ ++b;

printf("\n%d",c);

(A) 23

(B) 22

(C) 30

(D) Compilation Error

Answer : 23 //a=10(no of digit in a) so 2;//2+(21)=23;// If there is any (\t,\n escape sequence )also
get 1;

4)

Given the following program fragment

main ()

{
int i, j, k;

i = 3;

 j =2*(i++); //i=3 (2*3)=6 ,next line I will be 4;

 k =2*(++i); //i=4 (2*5) =10;

which one of the given option is correct?

(A) j = 6, k = 10.

(B) i = 5, k = 6.

(C) j = 6, k = 8.

(D) i = 4, j = 6.

Answer : j = 6, k = 10.

5)

main() 

int x=5; 

printf("%d,%d,%d",x,x<<2,x>>2); //left shift= remove 2 digits left and add 2 0s to right (x*2^y)

//right shift=remove 2 digits from right and add 2 0s to left (x/2^y)


}

(A) 5,21,1

(B) 5,20,1

(C) 5,19,0

(D) 5,19,1

Answer : 5,20,1

6)

void main(){

int a=80;
if(a++>80) // a=80 next line a=81;

printf("welcome%d",a);

else

printf("hello%d",a); //a=81

(A) hello 81

(B) welcome 81

(C) hello 80

(D) welcome 80

Answer : hello 81

7)

what is the output of following program?

void main(){

float a;

a=6.7;

if(a==6.7) //float is not equal

printf("A");

else

printf("B");

(A) A

(B) B

(C) error

(D) nothing display on screen

Answer : B

8)
what is the output of following program?

void main(){

int a;

a=1;

while(a-->=1) // --> is combination of 2 (decrement + greater than )

while(a-->=0);

printf("%d",a);

(A) 3

(B) -3

(C) 0

(D) error

Answer : -3

9)

what is the output of following program?

void main(){

int a=1;

void xyz(int , int);

xyz(++a,a++); //right to left precendce for incre and decr

xyz(a++,++a); //right to left precendce for incre and decr;

printf("%d",a);

void xyz(int x, inty){

printf("%d%d",x,y);

(A) 3 1 3 4 5
(B) 3 1 4 4 5

(C) 3 1 4 4 4

(D) 3 1 4 5 5

Answer : 3 1 4 4 5

10)

How many times the while loop will get executed?

main ( )

int a = 1 ;

while ( a <= 100) ;

printf ( â??%dâ??, a++ ) ;

(A) 100

(B) 1

(C) 0

(D) Infinite

Answer : Infinite

11)

What is the output of the following program?

void main(){

int a;

a=10;

while(a++<=15)
printf("%d",a);

printf("%d",a+10);

(A) 10 11 12 13 14 15 16

(B) 11 12 13 14 15 16 27

(C) 10 11 12 13 14 15 25

(D) 11 11 12 13 14 15 25

Answer : 11 12 13 14 15 16 27

12)

What is the output of the following program?

void xyz(int p1, int *p2){

++p1;

++*p2;

printf("%d%d",p1,*p2);

void main(){

int a=10;

xyz(a++,++*(&a));

xyz(a++,++*(&a));

printf("%d",a);

(A) 10 11 13 14 14

(B) 11 12 14 15 15

(C) 12 13 15 16 16

(D) 11 12 13 14 14

Answer : 12 13 15 16 16

13)
What is the output of the following program?

void main(){

int a,b;

a=b=10;

while(a)

a=b++<=13;

printf("%d%d",a,b);

printf("%d%d",a+10,b+10);

(A) 1 11 1 12 1 13 1 14 0 15 a=10 b=25

(B) 0 11 1 12 1 13 1 14 0 15 a=10 b=25

(C) 1 11 1 12 1 13 1 14 0 15 a=11 b=25

(D) 0 11 1 12 1 13 1 14 0 15 a=10 b=25

Answer : 1 11 1 12 1 13 1 14 0 15 a=10 b=25

14)

What is the output of the following program?

void main(){

int a;

a=1;

a++ * ++a;

printf("%d",a);

(A) 3
(B) 4

(C) 6

(D) 2

Answer : 3

15)

What is the output of the following program?

void main(){

int a,b;

a=b=1;

a=a++ + ++b;

b=b++ + ++a;

printf("%d%d",a,b);

`(A) 4 7

(B) 5 7

(C) 4 8

(D) 4 6

Answer : 4 6

16)

What is the output of the following program?

void xyz(int p1, int *p2){

++p1;

++*p2;

printf("%d%d",p1,*p2);

void main(){

int a=10;
xyz(a++,&a);

xyz(a++,&a);

printf("%d",a);

(A) 10 11 12 13 13

(B) 11 12 13 13 14

(C) 10 11 12 12 13

(D) 11 12 13 14 14

Answer : 11 12 13 14 14

17)

What is the output of the following program?

void main(){

int a=1;

while(a++<=1)

while(a++<=2);

printf("%d",a);

(A) 2

(B) 3

(C) 4

(D) 5

Answer : 5

18)

What is the output of the following program?

void main(){

int a;

a=1;
while(a<=1)

if(a%2)

printf("%d",a++);

printf("%d",a+10);

(A) 2 11

(B) 1 11

(C) 2 12

(D) 1 12

Answer : 1 12

19)

What will be the output of  the following program

 main( )

 { 

      int pskills[] = { 10, 20, 30, 40, 50 };

      int i, *ptr ;

      ptr = pskills;

      for ( i = 0 ; i <4 ; i++ )

     {

          fun(ptr++);

          printf ("\n%", *ptr ) ;

       }

 }

 void fun(int *i)

 {

      *i = *i + 1;

 }

(A) 11 21 31 41
(B) 20 30 40 50

(C) 21 31 41 51

(D) 10 20 30 40

Answer : 20 30 40 50

20)What is the output of following program?

void main(){

int a=2;

switch(a)

case 1: printf("A");

break;

case 2: printf("B");

continue; //java script not within a loop

case 3: printf("C");

break;

case 4; printf("D");

default: printf("E");

Answer : error

21)

void main(){

int a=2;

switch(a); //switch statement is terminated;

{
case 1: printf("A");

case 2: printf("B");

case 3: printf("C");

break;

case 4: printf("D");

default: printf("E");

break;

Answer : error

22)

What is the output of following program?

void main(){

int a=2;

switch(a)

case4: printf("A"); //case space 4;

break;

case3: printf("B");

case2: printf("C");

case1: printf("D");

break;

default: printf("E");

}
Answer : E

23)

What is the output of following program?

void main(){

int a=2;

switch(a)

case 4: printf("A");

break;

case 3: printf("B");

case default : printf("C"); //expected : before default;

case 1 : printf("D");

break;

case 5 : printf("E"); 

Answer : error

24) What is the output of following program?

void f1(){

extern int g;

static int s=5;

int a;

++g;

a=s++;

printf("%d%d%d",a,s,g);

if(a<=6)

f1();
printf("%d%d%d",a,s,g);

void f2(){

static int s;

int a;

a=++s;

++g; //g not declared

printf("%d%d%d",a,s,g);

if(a<=2)

f2();

printf("%d%d%d",a,s,g);

main(){

f1();

f2();

Answer : error

25)

What is the output of following program?

void main(){

int a;

a=1;

while(a<=10){

printf("%d",a);

if(a>3)

break;

a++;

}
printf("%d",a+10);

Answer : 1 2 3 4 14

1.ques:

2.A long double can be used if range of a double is not enough to accommodate a real number

1.Ans : TRUE

2.ques:Is there any difference in the #define and typedef in the following code?

typedef char * string_t; //name your data type

#define string_d char *; //alias name;

string_t s1, s2;

string_d s3, s4;

2.ANS : YES

3.ques: Function can return a floating point number.

3.ANS : TRUE

4.ques:function cannot be defined inside another function

4.ANS : TRUE

5.ques:can we use return keyword in the ternary operator?

5.ANS : NO
6.#include<stdio.h>

int check (int, int);

int main()

int c;

c = check(10, 20);

printf("c=%d\n", c);

return 0;

int check(int i, int j)

int *p, *q;

p=&i;

q=&j;

i>=45 ? return(*p): return(*q); //return statement error

6.ANS : COMPILE ERROR

7. How many times the program will print "IndiaBIX" ?

#include<stdio.h>

int main()

printf("IndiaBIX");
main();

return 0;

A.Infinite times

B.32767 times

C.65535 times

D.Till stack overflows

What will function gcvt() do?

A. Convert vector to integer value

B. Convert floating-point number to a string

C. Convert 2D array in to 1D array.

D. Covert multi Dimensional array to 1D array pointer.

8.What do the following declaration signify?

int (*pf)();

A.pf is a pointer to function.

B.pf is a function.

C.pf is a pointer to a function which return int

D.pf is a function of pointer variable.

8.ANS: C.pf is a pointer to a function which return int

9.QUES:By default structure variable will be of auto storage class

9.ANS : YES.
10.#include<stdio.h>

int main()

char *p;

p="%d\n";

p++;

p++;

printf(p-2, 23);

return 0;

A.21

B.23

C.Error

D.No output

10.ANS : 23

11.What will be the output of the program if the size of pointer is 4-bytes?

#include<stdio.h>

int main()

printf("%d, %d\n", sizeof(NULL), sizeof("")); //int size(NULL) = 4 // void size(NULL) = 8

return 0;

}
A.2, 1

B.2, 2

C.4, 1

D.4, 2

ANS : 4,1

12.#include<stdio.h>

int main()

char str[20] = "Hello";

char *const p=str;

*p='M';

printf("%s\n", str);

return 0;

A.Mello

B.Hello

C.HMello

D.MHello

12.ANS : Mello

14.Which of the structure is incorrcet?

1:

struct aa
{

int a;

float b;

};

2:

struct aa

int a;

float b;

struct aa var;

};

3:

struct aa

int a;

float b;

struct aa *var;

};

A.1

B.2

C.3

D.1, 2, 3

14.ANS : b.2
15.Left shifting an unsigned int or char by 1 is always equivalent to multiplying it by 2.

A.True

B.False

15.ANS : TRUE

16.Bitwise & can be used to check if more than one bit in a number is on.

A.True

B.False

16.ANS:TRUE

17.Which of the following is correct way to define the function fun() in the below program?

#include<stdio.h>

int main()

int a[3][4];

fun(a);

return 0;

A.

void fun(int p[][4])

{
}

B.

void fun(int *p[4])

C.

void fun(int *p[][4])

D.

void fun(int *p[3][4])

17.ANS : A

capps.txt

8. What will be the output of the following C code?

   #include <stdio.h>

   int main()
   {

       int i = 10;

       int *const p = &i;

       foo(&p);

       printf("%d\n", *p);

   }

   void foo(int **p)

   {

       int j = 11;

       *p = &j;

       printf("%d\n", **p);

   }

a) 11 11
b) Undefined behaviour
c) Compile time error
d) Segmentation fault/code-crash

9. Which of the following is the correct syntax to send an array as a parameter to function?
a) func(&array);
b) func(#array);
c) func(*array);
d) func(array[size]);

10. Which of the following can never be sent by call-by-value?


a) Variable
b) Array
c) Structures
d) Both Array and Structures

11. Which type of variables can have same name in different function?
a) global variables
b) static variables
c) Function arguments
d) Both static variables and Function arguments

12. Arguments that take input by user before running a program are called?
a) main function arguments
b) main arguments
c) Command-Line arguments
d) Parameterized arguments

13. What is the maximum number of arguments that can be passed in a single function?
a) 127
b) 253
c) 361
d) No limits in number of arguments

14. What will be the output of the following C code?

   #include <stdio.h>

   void m(int *p, int *q)

   {

       int temp = *p; *p = *q; *q = temp;

   }

   void main()

   {
       int a = 6, b = 5;

       m(&a, &b);

       printf("%d %d\n", a, b);

   }

a) 5 6
b) 6 5
c) 5 5
d) 6 6

15. What will be the output of the following C code?

   #include <stdio.h>

   void m(int *p)

   {

       int i = 0;
       for(i = 0;i < 5; i++)

       printf("%d\t", p[i]);

   }

   void main()

   {

       int a[5] = {6, 5, 3};

       m(&a);

   }

a) 0 0 0 0 0
b) 6 5 3 0 0
c) Run time error
d) 6 5 3 junk junk

16. What will be the output of the following C code?


   #include <stdio.h>

   void m(int p, int q)

   {

       int temp = p;

       p = q;

       q = temp;

   }

   void main()

   {

       int a = 6, b = 5;
       m(a, b);

       printf("%d %d\n", a, b);

   }

a) 5 6
b) 5 5
c) 6 5
d) 6 6

17. What will be the output of the following C code?

   #include <stdio.h>

   void m(int p, int q)

   {

       printf("%d %d\n", p, q);

   }
   void main()

   {

       int a = 6, b = 5;

       m(a);

   }

a) 6
b) 6 5
c) 6 junk value
d) Compile time error

18. What will be the output of the following C code?

   #include <stdio.h>

   void m(int p)

   {
       printf("%d\n", p);

   }

   void main()

   {

       int a = 6, b = 5;

       m(a, b);

       printf("%d %d\n", a, b);

   }

a) 6
b) 6 5
c) 6 junk value
d) Compile time error

 
 

19. What will be the output of the following C code?

   #include <stdio.h>

   void main()

   {

       int a[3] = {1, 2, 3};

       int *p = a;

       printf("%p\t%p", p, a);

   }

a) Same address is printed


b) Different address is printed
c) Compile time error
d) Nothing

 
20. What will be the output of the following C code?

   #include <stdio.h>

   void main()

   {

       char *s = "hello";

       char *p = s;

       printf("%p\t%p", p, s);

   }

a) Different address is printed


b) Same address is printed
c) Run time error
d) Nothing

21. What will be the output of the following C code?


   #include <stdio.h>

   void main()

   {

       char *s= "hello";

       char *p = s;

       printf("%c\t%c", p[0], s[1]);

   }

a) Run time error


b) h h
c) h e
d) h l

 
 

22. What will be the output of the following C code?

   #include <stdio.h>

   void main()

   {

       char *s= "hello";

       char *p = s;

       printf("%c\t%c", *(p + 3),  s[1]);

   }

a) h e
b) l l
c) l o
d) l e

 
 

23. What will be the output of the following C code?

   #include <stdio.h>

   void main()

   {

       char *s= "hello";

       char *p = s;

       printf("%c\t%c", 1[p], s[1]);

   }

a) h h
b) Run time error
c) l l
d) e e

 
24. What will be the output of the following C code?

   #include <stdio.h>

   void foo( int[] );

   int main()

   {

       int ary[4] = {1, 2, 3, 4};

       foo(ary);

       printf("%d ", ary[0]);

   }

   void foo(int p[4])


   {

       int i = 10;

       p = &i;

       printf("%d ", p[0]);

   }

a) 10 10
b) Compile time error
c) 10 1
d) Undefined behaviour

25. What will be the output of the following C code?

   #include <stdio.h>

   int main()

   {

       int ary[4] = {1, 2, 3, 4};


       int *p = ary + 3;

       printf("%d\n", p[-2]);

   }

a) 1
b) 2
c) Compile time error
d) Some garbage value

#include
main()
{
char s[]={'a','b','c','\n','c','\0'};
char *p,*str,*str1;
p=&s[3];
str=p;
str1=s;
printf("%d",++*p + ++*str1-32);
}

Answer: 77

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

Answer:
Compiler Error

  #include
main()
{
struct xx
{
int x;
struct yy
{
char s;
            struct xx *p;
};
struct yy *q;
};
}

Answer:
Compiler Error

 #define square(x) x*x


main()
{
int i;
i = 64/square(4);
printf("%d",i);
}

Answer:
64

main()
{
printf("%p",main);
}

Answer:
      Some address will be printed.

 main()
{
 extern int i;
 i=20;
 printf("%d",sizeof(i));
}

Answer:
Linker error: undefined symbol '_i'.

In which header file is the NULL macro defined?

A. stdio.h

B. stddef.h

C. stdio.h and stddef.h

D. math.h

Answer : c

8. What will be the output of the program ?

A. 30

B. 27

C. 9
D. 3

Answer : a

9. What will be the output of the program ?

#include<stdio.h>

void fun(void *p);

int i;

int main()

void *vptr;

vptr = &i;

fun(vptr);

return 0;

void fun(void *p)

int **q;

q = (int**)&p;

printf("%d\n", **q);

A. Error: cannot convert from void** to int**

B. Garbage value

C. 0

D. No output
Answer : c

10. What will be the output of the program ?

#include<stdio.h>

int main()

char *str;

str = "%s";

printf(str, "K\n");

return 0;

A. Error

B. No output

C. K

D. %s

Answer : Option C

11. What will be the output of the program ?

#include<stdio.h>

int *check(static int, static int);

int main()

int *c;

c = check(10, 20);
printf("%d\n", c);

return 0;

int *check(static int i, static int j)

int *p, *q;

p = &i;

q = &j;

if(i >= 45)

return (p);

else

return (q);

A. 10

B. 20

C. Error: Non portable pointer conversion

D. Error: cannot use static for function parameters

Answer : d

12. What will be the output of the program if the size of pointer is 4-bytes?

#include<stdio.h>

int main()

printf("%d, %d\n", sizeof(NULL), sizeof(""));

return 0;
}

A. 2, 1

B. 2, 2

C. 4, 1

D. 4, 2

Answer : Option C

What will be the output of the program ?

#include<stdio.h>

int main()

void *vp;

char ch=74, *cp="JACK";

int j=65;

vp=&ch;

printf("%c", *(char*)vp);

vp=&j;

printf("%c", *(int*)vp);

vp=cp;

printf("%s", (char*)vp+2);

return 0;

}
A. JCK

B. J65K

C. JAK

D. JACK

Answer :  Option D

14. What will be the output of the following C code?

#include <stdio.h>

int main()

int ary[4] = {1, 2, 3, 4};

int *p = ary + 3;

printf("%d %d\n", p[-2], ary[*p]);

a) 2 3

b) Compile time error

c) 2 4

d) 2 somegarbagevalue

ANSWER: d

15.  What will be the output of the following C code?

#include <stdio.h>

int main()
{

const int ary[4] = {1, 2, 3, 4};

int *p;

p = ary + 3;

*p = 5;

printf("%d\n", ary[3]);

a) 4

b) 5

c) Compile time error

d) 3

ANSWER : b

16.   What will be the output of following program ?

#include <stdio.h>

#define MAX 10

int main()

int array[MAX]={1,2,3},tally;

for(tally=0;tally< sizeof(array)/sizeof(int);tally+=1)

printf("%d ",*(tally+array));

return 0;

1.   Error

2.  1 3 4 5 6 7 8 9 10 11

3. 1 2 3 0 0 0 0 0 0 0

4. 0 0 0 0 0 0 0 0 0 0
ANSWER : 3

17. What will be the output of the program ?

#include<stdio.h>

int main()

char str[] = "peace";

char *s = str;

printf("%s\n", s++ +3);

return 0;

A. peace

B. eace

C. ace

D. ce

Answer :  Option D

18. What will be the output of the program ?

#include<stdio.h>

power(int**);

int main()
{

int a=5, *aa; /* Address of 'a' is 1000 */

aa = &a;

a = power(&aa);

printf("%d\n", a);

return 0;

power(int **ptr)

int b;

b = **ptr***ptr;

return (b);

A. 5

B. 25

C. 125

D. Garbage value

Answer : Option B

19.   Find the output

main()
            {
            char *str1="abcd";
            char str2[]="abcd";
            printf("%d %d %d",sizeof(str1),sizeof(str2),sizeof("abcd"));
            }

Answer:
255
20. What is the output generated on execution of the following C Program?

#include<stdio.h>

int main()

{    

struct emp    

{         

char name[20];        

int age;        

float sal;  

  };    

struct emp e = {"Ashok"};   

 printf("%d, %f\n", e.age, e.sal);   

 return 0;

Ans : o , o.oooooo

21. What is the output of the following program?

#include<stdio.h>

int main()

int x = 10, y = 20, z = 5, i;

i = x < y < z;  

printf("%d\n", i);

return 0;

Ans : 1

22. What is the output of the following program?

#include<stdio.h>
int main()

int a = 500, b = 100, c;

if(!a >= 400)

b = 300;

c = 200;

printf("b = %d c = %d\n", b, c);

return 0;

Ans : 100,200

23. Predict the output generated on execution of the following program:

#include<stdio.h>

#include<conio.h>

void main()

int const * p=5;

printf("%d",++(*p));  

Ans : compile error : can’t modify a const value

24. What will be the output of the following program?

#include<stdio.h>

#include <conio.h>

void main()

int c=- -2;

clrscr();

printf("c=%d",c);
getch();

Ans : c=2

25. What will be the output of the following program?

#include<stdio.h>

#include <conio.h>

void main()

clrscr();

printf("\nab");

printf("\bsi");

printf("\rha");

getch();

Ans : hai

1. What will be the output of the C program?

#include<stdio.h>

int main(){

int a = 130;

char *ptr;

ptr = (char *)&a;

printf("%d ",*ptr);

return 0;

A. -126 (Ans)

B. Run Time Error 

C. Garbage value
D. Compile Time Error

2. What will be the output of the C program?

#include<stdio.h>

int main(){

int i = 3;

int *j;

int **k;

j = &i;

k = &j;

k++;

printf("%d ",**k);

return 0;

A. Garbage value

B. Compilation Error  (Ans)

C. Run time error

D. Linker Error

3. What will be the output of the C program?

#include<stdio.h>

int main(){

int i = 3;

int *j;

j = &i;

j++;

printf("%d ",*j);
return 0;

A. Linker Error 

B. Run time error 

C. Compilation Error 

D. Garbage value  (Ans)

4. What will be the output of the C program?

#include<stdio.h>

#include<string.h>

int main(){

char *ptr = "hello";

char a[22];

strcpy(a, "world");

printf("\n%s %s",ptr, a);

return 0;

A. hello world  (Ans)

B. Run time error 

C. Compilation Error 

D. Garbage value 

5. What will be the output of the C program?

#include<stdio.h>

#include<string.h>

int main(){

char *ptr = "hello";


char a[22];

*ptr = "world";

printf("\n%s %s",ptr, a);

return 0;

A. Linker Error

B. Run time error

C. Compilation Error (Ans)

D. Garbage value

6. What will be the output of the C program?

#include<stdio.h>

int main()

char *ptr = "helloworld";

printf(ptr + 4);

return 0;

A. oworld (Ans)

B. world

C. hell

D. hello

7. What will be the output of the C program?

#include<stdio.h>

int main()

char *ptr = "2345";


printf("%c\n",*&*ptr);

return 0;

A. Address of 2

B. Compilation Error 

C. 2 (Ans)

D. Run time error

8. What will be the output of the C program?

#include<stdio.h>

#include<string.h>

int main(){

register a = 1;

int far *ptr;

ptr = &a;

printf("%u",ptr);

return 0;

A. Address of a

B. Run time error 

C. Garbage value

D. Compile time error (Ans)


9. What will be the output of the C program?

#include<stdio.h>

#include<string.h>

int main(){

char a = 30, b = 5;

char *p = &a, *q = &b;

printf("%d", p - q);

return 0;

A. 1 (Ans)

B. Run time error

C. Compilation Error

D. 25

10. What will be the output of the C program?

#include<stdio.h>

int main(){

int *ptr, b;

b = sizeof(ptr);

printf("%d" , b);

return 0;

A. 2

B. 4 (Ans)

C. Compilation Error 

D. Run time error 


11. What will be the output of the C program?

#include<stdio.h>

struct classroom

int students[7];

};

int main()

struct classroom cr = {2, 3, 5, 7, 11, 13};

int *ptr;

ptr = (int *)&cr;

printf("%d",*(ptr + 4));

return 0;

A. 5

B. 11 (Ans)

C. 13

D. 7

12. What will be the output of the C program?

#include<stdio.h>

unsigned long int (*function())[5]{

static unsigned long int arr[5] = {2, 3, 5, 7, 11};

printf("%d", *arr);

return &arr;

int main(){
unsigned long int (*ptr)[5];

ptr = function();

printf("%d", *(*ptr + 4));

return 0;

A. 2, 5

B. 2, 7

C. 2, 11 (Ans)

D. Compilation error

13. What will be the output of the C program?

#include<stdio.h>

int main(){

int a = 25, b;

int *ptr, *ptr1;

ptr = &a;

ptr1 = &b;

b = 36;

printf("%d %d",*ptr, *ptr1);

return 0;

A. 25 45632845 

B. Run time error 

C. Compilation Error 

D. 25 36  (Ans)

14. What will be the output of the C program?


#include<stdio.h>

int main(){

int * ptr ;

printf("%d", sizeof(ptr));

return 0;

A. 4 (Ans)

B. 8

C. 2

D. compilation error

15. What will be the output of the C program?

#include<stdio.h>

int main(){

int *ptr = 2;

printf("%d", sizeof(ptr));

return 0;

A. Garbage value

B. 2

C. Compilation error (Ans)

D. 4

16. What will be the output of the C program?

#include<stdio.h>

int main(){
int *ptr;

*ptr = 5;

printf("%d" , *ptr);

return 0;

A. compilation error

B. Runtime error (Ans)

C. 5

D. linker error

17. What will be the output of the C program?

#include<stdio.h>

int main(){

int a = 36;

int *ptr;

ptr = &a;

printf("%u %u", *&ptr , &*ptr);

return 0;

A. Address Value

B. Value Address

C. Address Address (Ans)

D. Compilation error

18. What will be the output of the C program?


#include<stdio.h>

int main(){

int num = 10;

printf("num = %d addresss of num = %u",num, &num);

num++;

printf("\n num = %d addresss of num = %u",num, &num);

return 0;

A. Compilation error

B. num = 10 address of num = 2293436 


    num = 11 address of num = 2293438 

C. num = 10 address of num = 2293436 


    num = 11 address of num = 2293440 

D. num = 10 address of num = 2293436 


    num = 11 address of num = 2293436  (Ans)

19. What will be the output of the C program?

#include<stdio.h>

int main(){

int i = 25;

int *j;

int **k;

j = &i;

k = &j;

printf("%u %u %u ",k,*k,**k);

return 0;

A. address address value (Ans)

B. address value value


C. address address address

D. compilation error

20. What will be the output of the C program?

#include<stdio.h>

int main(){

int a, b, c;

char *p = 0;

int *q = 0;

double *r = 0;

a = (int)(p + 1);

b = (int)(q + 1);

c = (int)(r + 1);

printf("%d %d %d",a, b, c);

return 0;

A. Runtime error

B. 0 0 0

C. Compilation error

D. 1 4 8 (Ans)

21. What will be the output of the C program?

#include<stdio.h>

int main()

char *ptr;

char string[] = "learn C pointers";


ptr = string;

ptr += 6;

printf("%s",ptr);

return 0;

A. compilation error

B. Runtime error

C. pointers

D. C pointers (Ans)

22. What will be the output of the C program?

#include<stdio.h>

int main()

const int a = 5;

const int *ptr;

ptr = &a;

*ptr = 10;

printf("%d\n", a);

return 0;

A. Compilation error (Ans)

B. Garbage Value 

C. Address

D. 5

23. What will be the output of the C program?


#include<stdio.h>

int main()

printf("%d", sizeof(void *));

return 0;

A. 1

B. compilation error 

C. Runtime error

D. 4 (Ans)

24. What will be the output of the C program?

#include<stdio.h>

void function(char**);

int main()

char *arr[] = { "ant", "bat", "cat", "dog", "egg", "fly" };

function(arr);

return 0;

void function(char **ptr)

char *ptr1;

ptr1 = (ptr += sizeof(int))[-2];

printf("%s\n", ptr1);

A. cat (Ans)

B. bat
C. dog

D. egg

25. What will be the output of the C program?

#include<stdio.h>

int main()

struct node

int a, b, c;

};

struct node num = {3, 5, 6};

struct node *ptr = & num;

printf("%d\n", *((int*)ptr + 1 + (3-2)));

return 0;

A. 3

B. 5

C. Compilation error

D. 6 (Ans)
26. What will be the output of the C program?

#include<stdio.h>

int main(){

char *ptr = "Pointer in c", arr[15];

arr[15] = *ptr;

printf("%c",arr[0]);

return 0;

A. Garbage value (Ans)

B. Run time error 

C. P

D. Compile time error

27. What will be the output of the C program?

#include<stdio.h>

int main(){

char arr[15] = "pointer array";

int *ptr;

ptr = arr;

printf("%c",ptr[1]);

return 0;

A. Garbage value

B. o 

C. t (Ans)

D. Compile time error


28. What will be the output of the C program?

#include<stdio.h>

int main()

int a = 10, b = 6;

int *ptr;

ptr = &b;

printf(" %d ", a **ptr);

return 0;

A. Pointer type error 

B. Run time error 

C. Compilation error

D. 60 (Ans)

29. What will be the output of the C program?

#include<stdio.h>

int main()

int *iptr;

int i, arr[2][2] = {10, 11, 12, 13};


iptr = *arr ;

printf("%d ", *(iptr+2));

return 0;

A. 12 (Ans)

B. 13 

C. Compilation Error 

D. Garbage value 

30. What will be the output of the C program?

#include<stdio.h>

int main()

char *cities[] = {"Delhi", "London", "Sydney"};

int **i = &cities[0];

printf("%c\n", **i);

return 0;

A. Delhi

B. Garbage address

C. D (Ans)

D. Compile Time Error

31. What will be the output of the C program?

#include<stdio.h>

int main(){

char *cities[] = {"UAE", "Spain", "America"};


int **i = &cities[0];

int **j = &cities[1];

int **k = &cities[2];

printf("%c%c%c\n", **i,**j,**k);

return 0;

A. Upa 

B. USA (Ans)

C. UAE

D. None of the above

32. What will be the output of the C program?

#include<stdio.h>

int main(){

char array[5] = "Knot", *ptr, i, *ptr1;

ptr = &array[1];

ptr1 = ptr + 3;

*ptr1 = 101;

for(i = 0; i < 4;i++)

printf("%c", *ptr++);

return 0;

A. not

B. Knot

C. note (Ans)

D. garbage value
33. What will be the output of the C program?

#include<stdio.h>

int main()

char *ptr = "Pointer-to-String", i;

printf("%s", ++ptr);

return 0;

A. Pointer-to-String 

B. o 

C. ointer-to-String (Ans)

D. None of the above

34. What will be the output of the C program?

#include<stdio.h>

int main()

char *str = "His";

int i;

for(i = 0; i < strlen(str); i++)

printf("%s", str++);

return 0;

A. Hisis  (Ans)

B. Hisiss 

C. HisHisHis 

D. None of the above


35. What will be the output of the C program?

#include<stdio.h>

int main()

char arr[10] = "Mango", *ptr;

ptr = (&arr[1]++);

printf("%s",ptr++);

return 0;

A. ango

B. ngo

C. Compile time error (Ans)

D. Mango

36. What will be the output of the C program?

#include<stdio.h>

int main(){

int i = 5;

void *vptr;

vptr = &i;

printf("\nValue of iptr = %d ", *vptr);

return 0;

A. 5

B. garbage address

C. garbage value

D. Compile time error (Ans)


37. Fill the question mark to get "void pointer" as an output?

#include<stdio.h>

int main(){

char *ptr = "void pointer";

void *vptr;

vptr = &ptr;

printf("%s" , ?);

return 0;

A. *(char **)vptr (Ans)

B. (char **)vptr

C. *(char *)vptr

D. (char *)vptr

38. What will be the output of the C program?

#include<stdio.h>

#define NULL "error";

int main()

char *ptr = NULL;

printf("%s",ptr);

return 0;

A. Run time error 

B. NULL 
C. error (Ans)

D. Compile time error

39. Which type of pointer is a most convention way of storing raw address in c programming?

A. Void pointer (Ans)

B. Null pointer 

C. Integer pointer 

D. Double pointer

40. Fill the question mark to get "5" as an output?

#include<stdio.h>

int main()

int i = 5,*ptr;

ptr= &i;

void *vptr;

vptr = &ptr;

printf("\nValue of iptr = %d ", ?);

return 0;

A. **(int **)vptr

B. **(int ***)vptr

C. **(int ****)vptr

D. All the above (Ans)


1) What will be the output of following program ?
#include <stdio.h>
#include <string.h>
int main()
{
   int val=0;
   char str[]="IncludeHelp.Com";

   val=strcmp(str,"includehelp.com");
   printf("%d",val);   
   return 0;
}

ans:Strings are not equal, hence strcmp will return -1.

2) What will be the output of following program ?


#include <stdio.h>
#include <string.h>

int main()
{
   char str[];
   strcpy(str,"Hello");
   printf("%s",str);
   return 0;
}

ans:Error: 'str' Unknown Size


At the time of str declaration, size is empty, it may be possible when you are initializing string with
declaration (like char str[]="Hello";

3) What will be the output of following program ?

#include <stdio.h>
int main()
{
   char str[8]="IncludeHelp";
   printf("%s",str);
   return 0;
}

ans:Error: Too many initializers/ array bounds overflow.

4) Which of the following function sets first n characters of a string to a given character?

A. strinit()
B. strnset()
C. strset()
D. strcset()
ans:Option B

Explanation:

Declaration:

char *strnset(char *s, int ch, size_t n); Sets the first n characters of s to ch

#include <stdio.h>
#include <string.h>

int main(void)
{
  char *string = "abcdefghijklmnopqrstuvwxyz";
  char letter = 'x';

  printf("string before strnset: %s\n", string);


  strnset(string, letter, 13);
  printf("string after  strnset: %s\n", string);

  return 0;
}
Output:

string before strnset: abcdefghijklmnopqrstuvwxyz

string after strnset: xxxxxxxxxxxxxnopqrstuvwxyz

5) How will you print \n on the screen?

A. printf("\n");
B. echo "\\n";
C. printf('\n');
D. printf("\\n");

and: D

6)The library function used to find the last occurrence of a character in a string is

A. strnstr()
B. laststr()
C. strrchr()
D. strstr()

ans:C
#include <string.h>
#include <stdio.h>
int main(void)
{
  char text[] = "I learn through IndiaBIX.com";
  char *ptr, c = 'i';

  ptr = strrchr(text, c);


  if (ptr)
     printf("The position of '%c' is: %d\n", c, ptr-text);
  else
     printf("The character was not found\n");
  return 0;
}
Output:

The position of 'i' is: 19

7)Which of the following function is more appropriate for reading in a multi-word string?

A. printf();
B. scanf();
C. gets();
D. puts();
Answer: Option C

8)If the two strings are identical, then strcmp() function returns

ans: -1

9)What is (void*)0?

A. Representation of NULL pointer


B. Representation of void pointer
C. Error
D. None of above

ans: A

10)In which header file is the NULL macro defined?

A. stdio.h
B. stddef.h
C. stdio.h and stddef.h
D. math.h

ans: C

11)If a variable is a pointer to a structure, then which of the following operator is used to access data
members of the structure through the pointer variable?
A. .
B. &
C. *
D. ->
ans: Option D

12)What would be the equivalent pointer expression for referring the array element a[i][j][k][l]?

A. ((((a+i)+j)+k)+l)
B. *(*(*(*(a+i)+j)+k)+l)
C. (((a+i)+j)+k+l)
D. ((a+i)+j+k+l)
ans: Option B

13)What does the following declaration mean?


int (*ptr)[10];

A. ptr is array of pointers to 10 integers


B. ptr is a pointer to an array of 10 integers
C. ptr is an array of 10 integers
D. ptr is an pointer to array
ans: Option B

14)In C, if you pass an array as an argument to a function, what actually gets passed?

A. Value of elements in array


B. First element of the array
C. Base address of the array
D. Address of the last element of array

ans:C

15)main()
           {
           static int var = 5;
           printf("%d ",var--);
           if(var)
                       main();
           }

Answer:
54321
When static storage class is given, it is initialized once. The change in the value of a static variable is
retained even between the function calls. Main is also treated like any other ordinary function, which
can be called recursively.

16)What will be the output of following program ?


#include <stdio.h>
int main()
{
   char    *str="IncludeHelp";
   printf("%c\n",*&*str);
   return 0;
}

ans:I
& is a reference operator, * is de-reference operator, We can use these operators any number of
times. str points the first character of IncludeHelp, *str points "I", * & again reference and de-
reference the value of str.

17)What will be the output of following program ?

#include <stdio.h>
int main()
{
   int MAX=10;
   int array[MAX];
   printf("size of array is = %d",sizeof(array);
   return 0;
}

ans:size of array is = 40

18)Which is an incorrect declaration of one dimensional array ?


int x[5];
int x[5]={1,2,3,4,5};
int x[5]={1,2};
int x[];

ans:4
You can ignore value within the subscript [] when you are initialising array with elements, but here no
initialisation found.

19)#include <stdio.h>

int main()
{
   int arr[5];
    
   // Assume that base address of arr is 2000 and size of integer
       // is 32 bit
   arr++;
   printf("%u", arr);
    
   return 0;
}
1.2002

2.2004

3.2020

4.lvalue required
ans:4
Array name in C is implemented by a constant pointer. It is not possible to apply increment and
decrement on constant types.

20)Predict output of following program


int main()
{
   int i;
   int arr[5] = {1};
   for (i = 0; i < 5; i++)
       printf("%d ", arr[i]);
   return 0;
}

ans:10000
If we initialize an array with fewer members, all remaining members are automatically initialized as 0.

21)Consider the following declaration of a 奏 wo-dimensional array in C:


char a[100][100];
Run on IDE
Assuming that the main memory is byte-addressable and that the array is stored starting from
memory address 0, the address of a[40][50] is (GATE CS 2002)
A.4040
B.4050
C.5040
D.5050
ans:C
Address of a[40][50] = Base address + 40*100*element_size + 50*element_size
                     = 0 + 4000*1 + 50*1
                    = 4050

22)# include <stdio.h>

int main()
{
  char str1[] = "GeeksQuiz";
  char str2[] = {'G', 'e', 'e', 'k', 's', 'Q', 'u', 'i', 'z'};
  int n1 = sizeof(str1)/sizeof(str1[0]);
  int n2 = sizeof(str2)/sizeof(str2[0]);
  printf("n1 = %d, n2 = %d", n1, n2);
  return 0;
}
ans:n1=10,n2=9

23)int main()
{
   char a[2][3][3] = {'g','e','e','k','s','q','u','i','z'};
   printf("%s ", **a);
   return 0;
}
ans: geeksquiz

We have created a 3D array that should have 2*3*3 (= 18) elements, but we are initializing only 9 of
them. In C, when we initialize less no of elements in an array all uninitialized elements become 曾 0' in
case of char and 0 in case of integers.

24)#include<stdio.h>
void swap(char *str1, char *str2)
{
 char *temp = str1;
 str1 = str2;
 str2 = temp;

  
int main()
{
 char *str1 = "Geeks";
 char *str2 = "Quiz";
 swap(str1, str2);
 printf("str1 is %s, str2 is %s", str1, str2);
 return 0;
}

ans:str1 is Geeks, str2 is Quiz


The above swap() function doesn't swap strings. The function just changes local pointer variables and
the changes are not reflected outside the function.

25)#include<stdio.h>
int main()
{
   char str[20] = "GeeksQuiz";
   printf ("%d", sizeof(str));
   return 0;
}
ans:20

ques.txt

Displaying ques.txt.

 
1. main() {   int c[ ]={2.8,3.4,4,6.7,5};
 int j,*p=c,*q=c;  
for(j=0;j<5;j++) {
  printf(" %d ",*c);      ++q;
 }  for(j=0;j<5;j++)
{ printf(" %d ",*p); ++p;   } }
Answer:              2 2 2 2 2 2 3 4 6 5      
  Explanation:  

Initially pointer c is assigned to both p and q. In the first loop, since only q is incremented and not c ,
the value 2 will be printed 5 times. In second loop p itself is incremented. So the values 2 3 4 6 5 will
be printed.   

2.
void main() {
int  const * p=5;
printf("%d",++(*p));
} Answer:   Compiler error: Cannot modify a constant value.  Explanation: p is a pointer to a "constant
integer". But we tried to change the value of the "constant integer".
3.
 main() {
 char *p;
printf("%d %d ",sizeof(*p),sizeof(p));

Answer:               1 2 Explanation: The sizeof() operator gives the number of bytes taken by its operand.
P is a character pointer, which needs one byte for storing its value (a character). Hence sizeof(*p)
gives a value of 1. Since it needs two bytes to store the address of the character pointer sizeof(p) gives
2.

4.
#include<stdio.h>
main() {
char s[]={'a','b','c','\n','c','\0'};
char *p,*str,*str1;
p=&s[3];
str=p;
str1=s;
printf("%d",++*p + ++*str1-32);
}
Answer: 77  

Explanation: p is pointing to character '\n'. str1 is pointing to character 'a' ++*p. "p is pointing to '\n'
and that is incremented by one." the ASCII value of '\n' is 10, which is then incremented to 11. The
value of ++*p is 11. ++*str1, str1 is pointing to 'a' that is incremented by 1 and it becomes 'b'. ASCII
value of 'b' is 98.  Now performing (11 + 98 – 32), we get 77("M"); So we get the output 77 :: "M"
(Ascii is 77).

5.

void main()
{
 char far *farther,*farthest;   
 printf("%d..%d",sizeof(farther),sizeof(farthest));    
 }

Answer: 4..2   Explanation: the second pointer is of char type and not a far pointer

6,
main()
{
char *p;  p="Hello";
printf("%c\n",*&*p);
} Answer: H
Explanation: * is a dereference operator & is a reference  operator. They can be applied any number
of times provided it is meaningful. Here  p points to the first character in the string "Hello". *p
dereferences it and so its value is H. Again  & references it to an address and * dereferences it to the
value H.

7.
main()

 static char names[5][20]={"pascal","ada","cobol","fortran","perl"};     int i; char *t;
    t=names[3];
    names[3]=names[4];
    names[4]=t;
    for (i=0;i<=4;i++)      printf("%s",names[i]);
} Answer: Compiler error: Lvalue required in function main Explanation: Array names are pointer
constants. So it cannot be modified.  
 

8.
# include <stdio.h>
int one_d[]={1,2,3};
main()
{
 int *ptr;   ptr=one_d;
 ptr+=3;
 printf("%d",*ptr);
} Answer: garbage value
Explanation: ptr pointer is pointing to out of the array range of one_d.  
9. # include<stdio.h>
aaa() {  
printf("hi");
} bbb(){  printf("hello");
} ccc(){  printf("bye");  
} main() {   int (*ptr[3])();
 ptr[0]=aaa;
  ptr[1]=bbb;
 ptr[2]=ccc;
 ptr[2](); } Answer: bye  
Explanation: ptr is array of pointers to functions of return type int.ptr[0] is assigned to address of the
function aaa. Similarly ptr[1] and ptr[2] for bbb and ccc respectively. ptr[2]() is in effect of writing
ccc(), since ptr[2] points to ccc.  

10.
In the following pgm add a  stmt in the function fun such that the address of  'a' gets stored in 'j'.
main(){
  int * j;  
void fun(int **);
 fun(&j);
 }
void fun(int **k) {  
int a =0;   /* add a stmt here*/  }
Answer:

 *k = &a
Explanation:          The argument of the function is a pointer to a pointer.        

11.
main() {
char *p;
p="%d\n";     
       p++;  
      p++;      
   printf(p-2,300);
} Answer:  300
Explanation: The pointer points to % since it is incremented twice and again decremented by 2, it
points to '%d\n' and 300 is printed.  

12.

void main()
{
 void *v;
int integer=2;
int *i=&integer;
v=i;
 printf("%d",(int*)*v);
}
Answer:  Compiler Error. We cannot apply indirection on type void*.
Explanation: Void pointer is a generic pointer type. No pointer arithmetic can be done on it. Void
pointers are normally used for,
1. Passing generic pointers to functions and returning such pointers. 2. As a intermediate pointer
type.
3. Used when the exact pointer type will be known at a later point of time.  

c app pointer and arrary.txt

Displaying c app pointer and arrary.txt.

1. What will be the output of the C program?

#include<stdio.h>

int main()

char *ptr;

char string[] = "learn C from 2braces.com";

ptr = string;

ptr += 6;

printf("%s",ptr);

return 0;

Ans: C from 2braces.com

2. What will be the output of the C program?

#include<stdio.h>

int main()

const int a = 5;

const int *ptr;

ptr = &a;
*ptr = 10;

printf("%d\n", a);

return 0;

Ans: address

3.What will be the output of the C program?

#include<stdio.h>

int main()

printf("%d", sizeof(void *));

return 0;

Ans: 4

4. What will be the output of the C program?

#include<stdio.h>

void function(char**);

int main()

char *arr[] = { "ant", "bat", "cat", "dog", "egg", "fly" };

function(arr);

return 0;

void function(char **ptr)

char *ptr1;

ptr1 = (ptr += sizeof(int))[-2];

printf("%s\n", ptr1);
}

Ans:  cat

5. What will be the output of the C program?

#include<stdio.h>

int main(){

char *ptr = "Pointer in c", arr[15];

arr[15] = *ptr;

printf("%c",arr[0]);

return 0;

Ans:  garbage value

6. What will be the output of the C program?

#include<stdio.h>

int main(){

char arr[15] = "pointer array";

int *ptr;

ptr = arr;

printf("%c",ptr[1]);

return 0;

Ans: t

7. What will be the output of the C program?

#include<stdio.h>

int main()

int a = 10, b = 6;

int *ptr;
ptr = &b;

printf(" %d ", a  **ptr);

return 0;

Ans: 60

8. Which type of pointer is a most convention way of storing raw address in c programming?    Ans:
void pointer

ARRAYS:

9.What will happen if in a C program you assign a value to an array element whose subscript exceeds
the size of array?

A. The element will be set to 0.

B. The compiler would report an error.

C. The program may crash if some important data gets overwritten.

D. The array size would appropriately grow.

Answer: Option C

10.What does the following declaration mean?

int (*ptr)[10];

A. ptr is array of pointers to 10 integers

B. ptr is a pointer to an array of 10 integers

C. ptr is an array of 10 integers

D. ptr is an pointer to array

Answer: Option B

 
11.What will be the output of the program ?

#include<stdio.h>

int main()

   int a[5] = {5, 1, 15, 20, 25};

   int i, j, m;

   i = ++a[1];

   j = a[1]++;

   m = a[i++];

   printf("%d, %d, %d", i, j, m);

   return 0;

A. 2, 1, 15

B. 1, 2, 5

C. 3, 2, 15

D. 2, 3, 20

Answer: Option C  

12.What will be the output of the program ?

#include<stdio.h>

int main()

   static int a[2][2] = {1, 2, 3, 4};


   int i, j;

   static int *p[] = {(int*)a, (int*)a+1, (int*)a+2};

   for(i=0; i<2; i++)

   {

       for(j=0; j<2; j++)

       {

           printf("%d, %d, %d, %d\n", *(*(p+i)+j), *(*(j+p)+i),

                                   *(*(i+p)+j), *(*(p+j)+i));

       }

   }

   return 0;

A. 1, 1, 1, 1

2, 3, 2, 3

3, 2, 3, 2

4, 4, 4, 4

B. 1, 2, 1, 2

2, 3, 2, 3

3, 4, 3, 4

4, 2, 4, 2

C. 1, 1, 1, 1

2, 2, 2, 2

2, 2, 2, 2

3, 3, 3, 3

D. 1, 2, 3, 4
2, 3, 4, 1

3, 4, 1, 2

4, 1, 2, 3

Answer: Option C

13.What will be the output of the program ?

#include<stdio.h>

int main()

   void fun(int, int[]);

   int arr[] = {1, 2, 3, 4};

   int i;

   fun(4, arr);

   for(i=0; i<4; i++)

       printf("%d,", arr[i]);

   return 0;

void fun(int n, int arr[])

   int *p=0;

   int i=0;

   while(i++ < n)

       p = &arr[i];

   *p=0;

A. 2, 3, 4, 5
B. 1, 2, 3, 4

C. 0, 1, 2, 3

D. 3, 2, 1 0

Answer: Option B

14.What will be the output of the program ?

#include<stdio.h>

void fun(int **p);

int main()

   int a[3][4] = {1, 2, 3, 4, 4, 3, 2, 8, 7, 8, 9, 0};

   int *ptr;

   ptr = &a[0][0];

   fun(&ptr);

   return 0;

void fun(int **p)

   printf("%d\n", **p);

A. 1

B. 2

C. 3

D. 4

Answer: Option A
 

15.What will be the output of the program if the array begins at 65472 and each integer occupies 2
bytes?

#include<stdio.h>

int main()

   int a[3][4] = {1, 2, 3, 4, 4, 3, 2, 1, 7, 8, 9, 0};

   printf("%u, %u\n", a+1, &a+1);

   return 0;

A. 65474, 65476

B. 65480, 65496

C. 65480, 65488

D. 65474, 65488

Answer: Option B

16.What will be the output of the program in Turb C (under DOS)?

#include<stdio.h>

int main()

   int arr[5], i=0;

   while(i<5)

       arr[i]=++i;
   for(i=0; i<5; i++)

       printf("%d, ", arr[i]);

   return 0;

A. 1, 2, 3, 4, 5,

B. Garbage value, 1, 2, 3, 4,

C. 0, 1, 2, 3, 4,

D. 2, 3, 4, 5, 6,

Answer: Option B

17.Predict the output of below program:

#include <stdio.h>

int main()

   int arr[5];

   arr++;

   printf("%u", arr);

   return 0;

A.2002

B.2004

C.2020

D.lvalue required

Answer: Option D
18.What will be the output of following program?

#include <stdio.h>

int main()

{   static int array[]={10,20,30,40,50};

   printf("%d...%d",*array,*(array+3)* *array);

   return 0;

A. Error

B. 10...40

C. 10...300

D. 10....400

Answer: Option D

19.What will be the output of following program ?

#include <stdio.h>

int main()

{   int a[5]={1,2,3,4,5},b[5]={10,20,30,40,50},tally;

    

   for(tally=0;tally< 5;++tally)

       *(a+tally)=*(tally+a)+ *(b+tally);

    

   for(tally=0;tally< 5;tally++)

       printf("%d ",*(a+tally));
   return 0;

A.  1 2 3 4 5

B. 10 20 30 40 50

C. 11 22 33 44 55

D. Error

Answer: Option C

20.What will be the output of following program?

#include <stdio.h>

int main()

{   int a[5]={0x00,0x01,0x02,0x03,0x04},i;

   i=4;

   while(a[i])

   {

       printf("%02d  ",*a+i);

       --i;

   }

   return 0;

A. 00 01 02 03 04

B. 04 03 02 01 00

C. 04 03 02 01

D. 01 02 03 04

Answer: Option C
.What will be the output of the C program?

#include<stdio.h>

int main()

int arr[5] = {1, 3, 5, 7, 11};

int *ptr, *ptr1;

ptr = &arr;

ptr1 = *ptr + 3;

printf("%d--%d", *ptr, ptr1);

A. 1--11

B. 1-7

C. 1--4

D. 1--some address

Option: C

Explanation

Here, ptr = &arr;

ptr = address of a first value in an array arr;

ptr1 = *(address of a first value in an array arr) + 3;

i.e) ptr1 = value of a first element in an array arr + 3;


i.e) ptr1 = 1 + 3;

i.e) ptr1 = 4;

printf("%d--%d", *ptr, ptr1);

printf("%d--%d", 1, 4);

Thus 1--4 is outputted.

--------------------------------------------------------------------------------------------

2.Fill the question mark to get "5" as an output?

#include<stdio.h>

int main()

int i = 5,*ptr;

ptr= &i;

void *vptr;

vptr = &ptr;

printf("\nValue of iptr = %d ", ?);

return 0;

A. **(int **)vptr

B. **(int ***)vptr

C. **(int ****)vptr

D. All the above


Option: D

Explanation

All declarations are true, because typecasting can be with more asterisks but not with lesser asterisks.

--------------------------------------------------------------------------------------------

3.What will be the output of the C program?

#include<stdio.h>

int main()

int a = 25, b;

int *ptr, *ptr1;

ptr = &a;

ptr1 = &b;

b = 36;

printf("%d %d",*ptr, *ptr1);

return 0;

A. 25 45632845

B. Run time error

C. Compilation Error

D. 25 36

Option: D

Explanation

ptr holds the address of a variableA and ptr1 holds the address of a variable B . The value of A is 25
and B is 36.

--------------------------------------------------------------------------------------------
4.Which type of pointer is a most convention way of storing raw address in c programming?

A. Void pointer

B. Null pointer

C. Integer pointer

D. Double pointer

Option: A

Explanation:

Void pointer is alone generic because void pointer does not have any associated data type with it.
Being generic void pointer can store raw address of a variable irrespective of it's datatype.

--------------------------------------------------------------------------------------------

5.What will be the output of the C program?

#include<stdio.h>

#define NULL "error";

int main()

char *ptr = NULL;

printf("%s",ptr);

return 0;

A. Run time error

B. NULL

C. error

D. Compile time error

Option: C

Explanation

NULL is used for stylistic convention. Thus NULL itself a macro which is defined in #include<stdio.h>
header files, thus modifing macro cause no error. Thus outputted "error"

--------------------------------------------------------------------------------------------
6. Fill the question mark to get "void pointer" as an output?

#include<stdio.h>

int main()

char *ptr = "void pointer";

void *vptr;

vptr = &ptr;

printf("%s" , ?);

return 0;

A. *(char **)vptr

B. (char **)vptr

C. *(char *)vptr

D. (char *)vptr

Option: A

In this program we used void pointer to display the string stored in another char pointer variable.
Thus by using pointer to pointer typecasting *(char **)vptr we outputted the string "void pointer"

--------------------------------------------------------------------------------------------

7. What will be the output of the C program?

#include<stdio.h>

#include<string.h>

int main()

char a = 30, b = 5;

char *p = &a, *q = &b;

printf("%d", p - q);
return 0;

A. 1

B. Run time error

C. Compilation Error

D. 25

Option: A

Explanation

Difference between any two variables of same data type are always one.

--------------------------------------------------------------------------------------------

8.What will be the output of the C program?

#include<stdio.h>

int main()

int a, b, c;

int arr[5] = {1, 2, 3, 25, 7};

a = ++arr[1];

b = arr[1]++;

c = arr[a++];

printf("%d--%d--%d", a, b, c);

return 0;

A. 4--3--25

B. 3--3--2

5
C. 4--4--25

D. 3--4--25

Option: A

here, a = ++arr[1];

i.e) a = 3 //arr[2];

b = arr[1]++;

i.e) b = 3 //arr[2];

c = arr[a++];

i.e) c = 25 //arr[4];

It must be noted that a value of a is increment ie ) a = 4;

printf("%d--%d--%d",a, b, c);

printf("%d--%d--%d",4, 3, 25);

Thus 4--3--25 is outputted.

--------------------------------------------------------------------------------------------

9.What will be the output of the C program?

#include<stdio.h>

int main()

int arr[5][5][5] = {0};

int *b = arr;

int *c = arr + 1;

printf("%d", c - b);

return 0;

A. 0

B. Runtime Error

C. 25
D. Some address

Option: C

Explanation

Clearly array arr[5][5][5] can hold upto 25 integer values.

let us consider the address of first element in an array arr[5][5][5] is 2292932

Now *b = 2292932; *c = arr + 1; i.e) *c contains the address which is located next to the last value
address in an arr[5][5][5], which is the address location next to that 25th value in an array arr[5][5][5].

Now *c = 2293032;

here, printf("%d", c-b);

printf("%d", 2292932 - 2293032);

printf("%d", 100); this is not yet over

printf("%d", 100/ sizeof(int)); as it is an integer type values we have to divide it by sizeof(int) to display
value not the address.

printf("%d", 25);

thus 25

--------------------------------------------------------------------------------------------

10.What will be the code to print 5 contains in a[4][1][0]?

#include<stdio.h>

int main()

int arr[ ]={1.2, 2.4, 3.6, 4.8, 5};

int j, *ptr = arr;

for(j = 0;j<5;j++)

printf("%d ", *arr);

++ptr;

}
A. 2 2 2 2 2

B. 1 1 1 1 1

C. 1 2 3 4 5

D. None of the above

Option: B

Explanation

Initially array arr is assigned to a pointer variable ptr. In the for loop, ptr is incremented and not arr.
So the value 1 1 1 1 1 will be printed. as we use integer type decimal values are all exempted.

--------------------------------------------------------------------------------------------

11.What will be the output of the C program?

#include<stdio.h>

int main()

int arr[5][5][5] = {0};

printf("%d", ( &arr+1 - &arr ));

return 0;

A. 0

B. Compilation error

C. 1

D. 4

--------------------------------------------------------------------------------------------

12.What will be the output of the C program?

#include<stdio.h>

int main()
{

static char *arr[ ] = {"bike", "bus", "car", "van"};

char **ptr[ ] = {arr+3, arr+2, arr+1, arr};

char ***p;

p = ptr;

**++p;

printf("%s",*--*++p + 2);

A. prints nothing

B. ke

C. ike

D. Compilation error

------------------------------------------------------------------------------------------

13.In C, if you pass an array as an argument to a function, what actually gets passed?

A.Value of elements in array

B.First element of the array

C.Base address of the array

D.Address of the last element of array

Answer: Option C

Explanation:

The statement 'C' is correct. When we pass an array as a funtion argument, the base address of the
array will be passed

--------------------------------------------------------------------------------------------

14.What will be the output of the C program?

#include<stdio.h>

void function(char**);

Int main()

{
char *arr[] = { "ant", "bat", "cat", "dog", "egg", "fly" };

function(arr);

return 0;

void function(char **ptr)

char *ptr1;

ptr1 = (ptr += sizeof(int))[-2];

printf("%s\n", ptr1);

A. cat

B. bat

C. dog

D. egg

Option: A

Explanation

Here function() gives the address of first value("ant") in an arr.This address is summationed by a
sizeof(int) which is 4. now the address in ptr points the value eggs, which is then reduced by 2 . now it
points to the value catwhich is finally displayed

--------------------------------------------------------------------------------------------

15.What will be the output of the C program?

#include<stdio.h>

int main()

char *ptr;

char string[] = "learn C from 2braces.com"; ptr = string;

ptr += 6;

printf("%s",ptr);

return 0;
}

A. compilation error

B. Runtime error

C. from 2braces.com

D. C from 2braces.com

Option: D

Explanation

Each letter in string[] array is stored in seperate address. The starting address in string[] array is stored
a pointer variable ptr which is then incremented by 6. Thus "learn " is neglected and "C from
2braces.com" is displayed.

--------------------------------------------------------------------------------------------

16.What will be the output of the C program?

#include<stdio.h>

int main()

printf("%d", sizeof(void *));

return 0;

A. 1

B. compilation error

C. Runtime error

D. 4

Option: D

sizeof void is 1 and the sizeof void pointer is 4

--------------------------------------------------------------------------------------------

17.What will be the output of the C program?

#include<stdio.h>
int main()

int *ptr = 2;

printf("%d", sizeof(ptr));

return 0;

A. Garbage value

B. 2

C. Compilation error

D. 4

Option: C

Explanation

ptr is the pointer variable of integer data type. Thus ptr can not be initialised by any integer value
other than 0.

--------------------------------------------------------------------------------------------

18.What will be the output of the C program?

#include<stdio.h>

int main()

char *ptr = "Pointer in c", arr[15];

arr[15] = *ptr;

printf("%c",arr[0]);

return 0;

A. Garbage value
B. Run time error

C. P

D. Compile time error

Option: A

Explanation

A pointer variable which is initialized by a string cannot to assigned to a array variable of size n. Thus
some garbage value or empty output will be displayed

--------------------------------------------------------------------------------------------

19.What will be the output of the C program?

#include<stdio.h>

int main()

int a = 10, b = 6;

int *ptr;

ptr = &b;

printf(" %d ", a **ptr);

return 0;

A. Pointer type error

B. Run time error

C. Compilation error

D. 60

Option: D

Explanation

The above program is simply a arithmetic pointer type.


i.e) a * *ptr

i.e) 10 * 6 = 60

--------------------------------------------------------------------------------------------

20.What will be the output of the C program?

#include<stdio.h>

int main()

int *iptr;

int i, arr[2][2] = {10, 11, 12, 13};

iptr = *arr ;

printf("%d ", *(iptr+2));

return 0;

A. 12

B. 13

C. Compilation Error

D. Garbage value

Option: A

Explanation:

Here, iptr holds the address of first element in an array arr i.e) address of 10. In printf statement we
increment the address by (2 * sizeof(int)). Thus iptr now points to the address of 12. Asterisks (*) in
printf statement prints the value inside the address i.e) 12 is outputted.

--------------------------------------------------------------------------------------------

22.What will be the output of the C program?

#include<stdio.h>

int main()

{
int arr[1] = {2};

printf("%d", 0[arr]);

return 0;

A. Compilation error

B. Some Garbage value

C. 2

D. 0

Option: C

Explanation

Watch clearly, arr[1] = {2}; is similar to

arr[1] = {2, '\0'};

Thus 0[arr] outputted 2

23.What will be the output of the C program?

#include<stdio.h>

void array(int **p);

int main()

int arr[2][3] = {{3, 6, 9 }, {12, 15, 18}};

int *ptr;

ptr = &arr;

array(&ptr);

return 0;

void array(int **p)


{

printf("%d", **p);

A. address of first element in array

B. 3

C. address of ptr

D. Runtime error

Option: B

Explanation

Here ptr = &arr.

i.e) ptr = address of first element in an array arr[2][3];

array(&ptr);

i.e) array(address of ptr);

Examine void array() funtion

void array(int **p)

i.e) void array(**(address of ptr))

i.e) void array(*(address of first element in an array arr[2][3]))

i.e) void array(value of first element in an array arr[2][3]);

i.e) void array(3)

printf("%d", **p);

i.e) printf("%d", 3);

Thus 3 is outputted.

24.What will be the output of the C program?

#include<stdio.h>
int main()

struct node { int a, b, c; };

struct node num = {3, 5, 6};

struct node *ptr = & num;

printf("%d\n", *((int*)ptr + 1 + (3-2)));

return 0;

A. 3

B. 5

C. Compilation error

D. 6

Option: D

Explanation

Here the pointer variable stores the address of first value in struct node num = {3, 5, 6}; which is
incremented by 2 and then the value 6 is finally displayed.

--------------------------------------------------------------------------------------------

25.What will be the output of the C program?

#include<stdio.h>

int main()

char *ptr = "Pointer-to-String", i;

printf("%s", ++ptr);

return 0;

A. Pointer-to-String

B. o
C. Pointer-to-String

D. None of the above

Option: C

Explanation

Here, the starting address i.e) The address of P is skipped by pre incrementing the address. "Noting
more than that".

1)When should we use pointers in a C program?


 1. To get address of a variable
 2. For achieving pass by reference in C: Pointers allow different functions to share and modify their
local variables.
 3. To pass large structures so that complete copy of the structure can be avoided.
 4. To implement “linked” data structures like linked lists and binary trees.
 
2) Can I use  “int” data type to store the value 32768? Why?
  No. “int” data type is capable of storing values from -32768 to 32767. To store 32768, you can use
“long int” instead.
  You can also use “unsigned int”, assuming you don’t intend to store negative values.
 
 
3) If a variable is a pointer to a structure, then which of the following operator is used to access data
members of the
   structure through the pointer variable?
 A. .
 B. &
 C. *
 D. ->
 Answer: Option D
 

4) Can you combine the following two statements into one?

char *p;
p = (char*) malloc(100);

 A. char p = *malloc(100);


 B. char *p = (char) malloc(100);
 C. char *p = (char*)malloc(100);
 D. char *p = (char *)(malloc*)(100);  
 Answer: Option C
  

5) In C, if you pass an array as an argument to a function, what actually gets passed?


 A. Value of elements in array
 B. First element of the array
 C. Base address of the array
 D. Address of the last element of array
 Answer: Option C
 
 
6) What does the following declaration mean?
  int (*ptr)[10];
 A. ptr is array of pointers to 10 integers
 B. ptr is a pointer to an array of 10 integers
 C. ptr is an array of 10 integers
 D. ptr is an pointer to array
 Answer: Option B  
 
7) What are the different types of real data type in C ?
 A. float, double
 B. short int, double, long int
 C. float, double, long double
 D. double, long int, float
 Answer: Option C

8) What will you do to treat the constant 3.14 as a long double?


 A. use 3.14LD
 B. use 3.14L
 C. use 3.14DL
 D. use 3.14LF
 Answer: Option B  
 
 
9) Which statement will you add in the following program to work it correctly?

#include<stdio.h>
int main()
{
   printf("%f\n", log(36.0));
   return 0;
}

A. #include<conio.h>
B. #include<math.h>
C. #include<stdlib.h>
D. #include<dos.h>
Answer: Option B  

10) The keyword used to transfer control from a function back to the calling function is
 A. switch
 B. goto
 C. go back
 D. return
 Answer: Option D
 
 
11) How many times the program will print "hello" ?

#include<stdio.h>
int main()
{
   printf("hello");
   main();
   return 0;
}

A. Infinite times
B. 32767 times
C. 65535 times
D. Till stack overflows
Answer: Option D  

12) What is (void*)0?


A. Representation of NULL pointer
B. Representation of void pointer
C. Error
D. None of above

Answer: Option A

13) If a variable is a pointer to a structure, then which of the following operator is used to access data
members of the structure through the pointer variable?
A. .
B. &
C. *
D. ->

Answer: Option D

14) What would be the equivalent pointer expression for referring the array element a[i][j][k][l]
A. ((((a+i)+j)+k)+l)
B. *(*(*(*(a+i)+j)+k)+l)
C. (((a+i)+j)+k+l)
D. ((a+i)+j+k+l)

Answer: Option B

15) The operator used to get value at address stored in a pointer variable is
A. *
B. &
C. &&
D. ||

Answer: Option A

16)Que – 2. Which of the following C code snippet is not valid?

(A) char* p = “string1”; printf(“%c”, *++p);


(B) char q[] = “string1”; printf(“%c”, *++q);
(C) char* r = “string1”; printf(“%c”, r[1]);
(D) None of the above

Solution: Option (A) is valid as p is a pointer pointing to character ‘s’ of “string1”. Using ++p, p will
point to character ‘t’ in “string1”. Therefore, *++p will print ‘t’.
Option (B) is invalid as q being base address of character array, ++q(increasing base address) is invalid.
Option (C) is valid as r is a pointer pointing to character ‘s’ of “string1”. Therefore,

r[1] = *(r+1) = ‘t’ and it will print ‘t’.

17)What will be the output of the following C code?

       #include <stdio.h>
       int main()

       {
char str[11] = "hello";
char *str1 = "world";
       strcat(str, str1);
       printf("%s %d", str, str[10]);    
       )
  

a) helloworld 0
b) helloworld anyvalue
c) worldhello 0
d) Segmentation fault/code crash
Answer: a

18)What will be the output of the program ?

#include<stdio.h>
#include<string.h>

int main()
{
   char str1[20] = "Hello", str2[20] = " World";
   printf("%s\n", strcpy(str2, strcat(str1, str2)));
   return 0;
}

a. Hello
b. Hello
c. Hello World
d. WorldHello

Answer: (c).

19) What will be the output of the program ?

#include<stdio.h>
int main()
{
   char p[] = "%d\n";
   p[1] = 'c';
   printf(p, 65);
   return 0;
}

a. A
b. a
c. c
d. 65
Answer: (a).

20)What will be the output of the program ?

#include<stdio.h>
#include<string.h>

int main()
{
   char str[] = "Compsci\0\Bits\0";
   printf("%s\n", str);
   return 0;
}

a. Bits
b. Compsci
c. Compsci Bits
d. Compsci\0Bits

Answer: (b).

21)Which one of the following statements is correct?


a. Array elements can be of integer type only.
b. The rank of an Array is the total number of elements it can contain.
c. The length of an Array is the number of dimensions in the Array.
d. The default value of numeric array elements is zero.

Answer: (d).

24) the operators > and < are meaningfull when used with pointers if,

A.The pointers point to data of similar type.

B.The pointers point to structure of similar data type.

C.The pointers point to elements of the same array.

D.None of these.

Answer: Option C

25)const int *ptr:

A.We cannot change the value pointed by ptr.


B.We cannot change the pointer ptr itself.

C.Both of the above

D.We can change the pointer as well as the value pointed by it.

Answer: Option A
Solution: int * : pointer to int
int const * : pointer to const int
int * const : const pointer to int
int const * const : const pointer to const int

Now the first const can be on either side of the type so:

const int * == int const *


const int * const == int const * const

So the above declaration is pointer to const int. Which means,we cannot change the value pointed by
ptr.

  

1.what will be the output?

main()

char *p;

p=”Hello”;

printf(“%c”,*&*p);

A. Hello

B. H

C. Some address will be printed

D. None of th

2.The address operator & cannot act on

a.R-values

b.Arithmetic expressionsc.Both of the value

c.Local variables
d.Member of structure

ans:c

3.#include<stdio.h>

main()

int i=10;

void *p=&i;

printf(“%d”,(int)*p);

a.compile time error

b.segmentation fault

c.10

d.undefined behaviour

ans:a

4.#include<stdio.h>

main()

int i=10;

void *p=&i;

printf(“%d”,*(float*)p);

Ans:0.000000

5.what do the following declaration signify?

char **argv;

a.argv is pointer to pointer

b.argv is function pointer

c.argv is pointer to char pointer

ans:c
6.#include<stdio.h>

int main()

int a[5]={2,3};

printf(“%d%d%d”,a[2],a[3],a[4]);

return 0;

a.garbage values

b.2,3,3

c.3,2,2

d.0,0,0

ans:d

7.In which header file NULL macro is defined?

a.stdio.h

b.stddef.h

c.stdio.h and stddef.h

ans:c

8.what is sizeof() in c?

a.operator

b.function

c.macro

d.none of these

ans:a

9.int main()

extern int i;

i=20;

printf(“%d”,sizeof(i));

return 0;
}

a.20

b.0

c.undefined reference to i/compilation error

ans:c

10.void main()

int a=printf(“cpp.com”);

printf(“%d”,a);

a.compilation error

b.0

c.cpp.com

d.cpp.com7

11.int main()

int x;

x=10,20,30;

printf(“%d”,x);

return 0;

a.10

b.20

c.10,20,30

d.compilation error

ans:10

11.how many times cppbuzz.com is printed?

void main()

int a=0;
while(a++<5)

printf(“cppbuzz.com”);

a.4

b.5

c.compilation error

d.0

ans:b11.how many times cppbuzz.com is printed?

void main()

int a=0;

while(a)

printf(“cppbuzz.com”);

a.4

b.infinite time

c.compilation error

d.0

ans:d

13.void main()

int a[10];

printf(“%d%d”,a[-1],a[12]);

a.0 0

b.garbage value,0

c.garbage value,garbage value

ans:c

14.#include<stdio.h>
void main()

int a[3][4]={1,2,3,4,4,3,2,1,7,8,9,0};

printf(“%u%u”,a+1,&a+1);

a.65474,65488

b.65490,65488

c.65480,65496

ans:c

15.the function sprint() works like printf but operates on____

a.data file

b.string

c.stdin

ans:b

1.Can you combine the following two statements into one?

      char *p;

      p=(char*)malloc(100);

A)char p = *malloc(100);

B)char *p = (char) malloc(100);

C)char *p = (char*)malloc(100);

D)char *p = (char *)(malloc*)(100);


Option:c

2. #include<stdio.h>

int main(){

int a = 130;

char *ptr;

ptr = (char *)&a;

printf("%d ",*ptr);

return 0;

A. -126

B. Run Time Error 

C. Garbage value

D. Compile Time Error

Option: A

Explanation

Here a variable a holds the value 130 of integer datatypes, which is then type casted to char
datatypes using pointer variable. As we know that a value 130 is exceeding the char range( -128 to
127), thus it loops through its range.

For Example

128 = -128
129 = -127
130 = -126
140 = -125

3. #include<stdio.h>

int main(){

int i = 3;

int *j;

int **k;

j = &i;
k = &j;

k++;

printf("%d ",**k);

return 0;

A.Garbage value

B. Compilation Error 

C. Run time error

D. Linker Error

Option: C

Explanation

Here k is the pointer variable which holds the address of another pointer variable j. where j is also a
pointer variable which also holds the address of another variable i. Now when the address of a
pointer variable k is incremented by 1 , then k hold some other garbage value which is not the address
of any other variable. Thus runtime error occurs.

4.#include<stdio.h>

int main(){

int i = 3;

int *j;

j = &i;

j++;

printf("%d ",*j);

return 0;

A.Linker error

B. Run time error 

C.Compilation error

D. Garbage value 

Option: D

Explanation
Here j is the pointer variable which holds the address of another variable called i. When j is
incremented, the address stored in j is incremented. As a result some garbage value will be displayed
as we had not initialized anything to the address next to the address of a variable i

5. #include<stdio.h>

#include<string.h>

int main(){

char *ptr = "hello";

char a[22];

*ptr = "world";

printf("\n%s %s",ptr, a);

return 0;

A. Linker Error

B. Run time error

C. Compilation Error

D. Garbage value

Option: C

Explanation

ptr is a pointer variable of character data type, string "world" can be set to the pointer variable ptr
only at the initializing time.

6. . What will be the output of the C program?

#include<stdio.h>

int main()

char *ptr = "2braces.com";

printf("%c\n",*&*ptr);

return 0;

A. Address of 2
B. Compilation Error 

C. 2

D. Run time error

Option: C

Explanation

In pointer, address operator and Multiplication operator are always cancel each other. Thus *&*ptr =
*ptr.

7. #include<stdio.h>

#include<string.h>

int main(){

register a = 1;

int far *ptr;

ptr = &a;

printf("%u",ptr);

return 0;

A. Address of a

B. Run time error 

C. Garbage value

D. Compile time error

Option: D

Explanation

"a" is a register variable which holds a value 1. It must be noted that variable a hold its value 1 in a
register but not in computer memory location thus the pointer variable ptr cannot hold the address of
a.

8. #include<stdio.h>

struct classroom

int students[7];
};

int main()

struct classroom cr = {2, 3, 5, 7, 11, 13};

int *ptr;

ptr = (int *)&cr;

printf("%d",*(ptr + 4));

return 0;

A. 5

B. 11

C. 13

D. 7

Option: B

Explanation

Here a pointer variable ptr holds the address of a first value (2) of an object cr, then the address of
the pointer variable is incremented by 4 and then its value is displayed .

9. #include<stdio.h>

int main(){

int a = 25, b;

int *ptr, *ptr1;

ptr = &a;

ptr1 = &b;

b = 36;

printf("%d %d",*ptr, *ptr1);

return 0;

A. 25 45632845 

B. Run time error 


C. Compilation Error 

D. 25 36 

Option: D

Explanation

ptr holds the address of a variable A and ptr1 holds the address of a variable B . The value ofA is 25
and B is 36.

10. #include<stdio.h>

int main(){

int * ptr ;

printf("%d", sizeof(ptr));

return 0;

A. 4

B. 8

C. 2

D. compilation error

Option: A

Explanation

size of int is 4 in 32 bits and 64bit operating system.

11. #include<stdio.h>

int main()

char temp;

char arr[10] = {1, 2, 3, 4, 5, 6, 9, 8};

temp = (arr + 1)[2];

printf("%d\n", temp);

return 0;

}
A. 2

B. 3

C. 4

D. 5

Option: C

Explanation

Here,temp=(arr+ 1)[2]; 
Let us consider the address of first element in an array arr[10] is 2293416 then temp looks like this
temp = (2293416 + 1)[2];
Now temp =(2293420)[2];, which denotes temp = "index value of 2 from the address 2293420(value =
2)";
Now temp = 4;(address = 2293428)
Thus the program outputted 4.

12. #include<stdio.h>

int main()

int a[1][2][3] = {0};

a[0][1][2] = 5;

printf("%d",*(*(*(a+0)+1)+2));

return 0;

A. printf("%d",*(((a+0)+1)+2));

B. printf("%d",*(*(*(a+0)+1)+2));

C. printf("%d",***((a+0)+1)+2);

D. None of the above

Option: B

Explanation

Simply, this is a format for naviting to a value using the address of a first element in an array.

13. #include<stdio.h>

void fun(char**);

int main()

{
char *arr[] = { "bat", "cat", "fat", "hat", "mat", "pat" };

fun(arr);

return 0;

void fun(char **p)

char *t;

t = (p += sizeof(int))[-1];

printf("%s\n", t);

A. mat

B. fat

C. hat

D. cat

Option: C

Explanation

fun(arr) returns the address of first element in an array arr Let we start from the function void fun().
*t is a pointer variable which holds t = (p += sizeof(int))[-1];
ie ) t = (p = p + sizeof(int)) [-1];
t = (p = p + 4) [-1]; 
t = (p = address of bat + 4)[-1];
let us consider a address of bat is 2293416,
t = (p = 2293416 + 4)[-1];
t = (p = 2293432)[-1]
t = ("mat")[-1]; // index from "mat" 
t = "hat"; 
thus hat is outputted.

14. #include<stdio.h>

int main()

int arr[5][5][5] = {0};

printf("%d", ( &arr+1 - &arr ));

return 0;
}

A. 0

B. Compilation error

C. 1

D. 4

Option: C

Explanation

printf("%d", (&arr+1 - &arr)); let us consider the address of an array arr starts from 2293420
then, printf("%d", (2293420 +1 - 2293420);
printf("%d", 0 + 1);
printf("%d", 1);
Thus 1 is outputted.

15. #include<stdio.h>

int main(){

int rows = 3, colums = 4, i, j, k;

int a[3][4] = {1, 2, 3, 5, 7};

i = j = k = 00;

for(i = 0;i<rows;i++)

for(j = 0;j<colums;j++)

if(a[k][j]<k)

k = a[i][j];

printf("%d\n", k);

return 0;

A. 00

B. No output

C. 0

D. 7

Option: C

Explanation
Initially we set i = 0, j = 0, k = 0. zero be never greater than any integer values in an array a[3][4], thus
if condition fails. and 0 is outputted.

16. #include<stdio.h>

int main()

int arr[ ]={1.2, 2.4, 3.6, 4.8, 5};

int j, *ptr = arr;

for(j = 0;j<5;j++)

printf("%d ", *arr);

++ptr;

A. 2 2 2 2 2

B. 1 1 1 1 1

C. 1 2 3 4 5

D. None of the above

Option: B

Explanation

Initially array arr is assigned to a pointer variable ptr. In the for loop, ptr is incremented and not arr.
So the value 1 1 1 1 1 will be printed. as we use integer type decimal values are all exempted.

17. #include<stdio.h>

int main()

int i = 0;

printf("Hello");

char s[4] = {'\b', '\t', '\r', '\n'};

for(i = 0;i<4;i++){

printf("%c", s[i]);

}
return 0;

A. Hello

B. Compilation error

C. Hell

D. None of the above

Option: C

Explanation

Hello is printed followed by \b\t\r\n. 


i.e) Hello\b\t\r\n. 
i.e) Hell\t\r\n. 
i.e) Hell        \r\n. 
i.e) Hell\n. 
i.e) Hell is Outputted.

18. #include<stdio.h>

int main()

int i = 0;

char s[4] = {'\0', '\0', '\0', '\0'};

for(i = 0;i<4;i++)

printf("%c", s[i]);

return 0;

A. \0 \0 \0

B. \0 \0 \0 \0

C. No output

D. None of the above

Option: C

Explanation
\0 = NULL. Thus compiler prints nothing.

19. #include<stdio.h>

int main()

char s[] = {'a', 'b', 'c', '\n', 'c', '\0'};

char *p, *str, *str1;

p = &s[3];

str = p;

str1 = s;

printf("%d", ++*p + ++*str1-32);

return 0;

A. 76

B. 77

C. 78

D. 79

Option: B

Explanation

p = &s[3].
i.e) p = address of '\n';
str = p;
i.e) str = address of p;
str1 = s;
str1 = address of 'a';
printf ("%d", ++*p + ++*str1 - 32);
i.e) printf("%d", ++\n + a -32);
i.e) printf("%d", 12 + 97 -32);
i.e) printf("%d", 12 + 65);
i.e) printf("%d", 77);
Thus 77 is outputted.

20. #include<stdio.h>

int main()

int i = 0;
printf("Hello");

char s[4] = {'\b', '\r', '\t', '\n'};

for(i = 0;i<4;i++)

printf("%c", s[i]);

return 0;

A. Hello

B. Hell

C. No output

D. Compilation error

Option: C

Explanation

Hello is printed followed by \b\r\t\n. 


i.e) Hello\b\r\t\n. 
i.e) Hell\r\t\n. 
i.e) \t\n. 
i.e)        \n. 
i.e)     is Outputted.ie(8 space is outputted)

21. #include<stdio.h>

int main()

int arr[2] = {1, 2, 3, 4, 5};

printf("%d", arr[3]);

return 0;

A. 3

B. 4

C. Some Garbage value

D. Compilation error
Option: C

Explanation

Here the size of an array is 2, but the value inside array is exceed 2. Thus it prints garbage value for
index more than 1

22. #include<stdio.h>

int main()

int arr[5] = {1, 3, 5, 7, 11};

int *ptr, *ptr1;

ptr = &arr;

ptr1 = *ptr + 3;

printf("%d--%d", *ptr, ptr1);

A. 1--11

B. 1-7

C. 1--4

D. 1--some address

Option: C

Explanation

Here, ptr = &arr;


ptr = address of a first value in an array arr;
ptr1 = *(address of a first value in an array arr) + 3;
i.e) ptr1 = value of a first element in an array arr + 3;
i.e) ptr1 = 1 + 3;
i.e) ptr1 = 4;
printf("%d--%d", *ptr, ptr1);
printf("%d--%d", 1, 4);
Thus 1--4 is outputted.

23. #include<stdio.h>

int main()

int arr[5] = { 1, 3, 5, 7, 11 };

int *ptr;
ptr = &arr;

printf("%d", *ptr + 1);

A. 1

B. 2

C. 3

D. Runtime error

Option: B

Explanation

Here ptr = &arr; 


ptr = address of a first value in an array arr; 
*ptr = value of a first element in an array arr; 
printf("%d", *ptr + 1); 
printf("%d", 1 + 1); 
Thus 2 is outputted.

24.#include <stdio.h>

int main()

    static int var[5];

    int count=0;

     

    var[++count]=++count;

    for(count=0;count<5;count++)

        printf("%d ",var[count]);

     

    return 0;

A.0 1 0 0 0

    B.0 2 0 0 0

   C.0 0 2 0 0
   D.0 0 0 0 0

Option C

25)

#include "stdio.h"

int main()

    char a[] = { 'A', 'B', 'C', 'D' };

    char* ppp = &a[0];

    *ppp++; // Line 1

    printf("%c %c ", *++ppp, --*ppp); // Line 2

OPTIONS: 
a)C B
b)B A
c)B C
d)C A

OUTPUT: (d) C A

Explanation: 
Line 1 : Now, ppp points to next memory location i.e., index 1 of the character array.
Line 2 : Firstly, –*ppp= –(*ppp) is executed and hence the value ‘B’ (which is in the index 1 position of
the char[] array) gets decremented by 1(i.e., it becomes ‘A’)and it is sent for printing. Then *++ppp=
*(++ppp) is executed which initially increments the pointer to the next element of the array and prints
the value in that index number 2 which is ‘C’. Although –*ppp is executed first compared to *++ppp,
the display will be shown in the order as we mentioned in the printf() function in line 2. Hence we get
output as C A.

1.Can you combine the following two statements into one?

      char *p;

      p=(char*)malloc(100);

A)char p = *malloc(100);

B)char *p = (char) malloc(100);

C)char *p = (char*)malloc(100);
D)char *p = (char *)(malloc*)(100);

Option:c

2. #include<stdio.h>

int main(){

int a = 130;

char *ptr;

ptr = (char *)&a;

printf("%d ",*ptr);

return 0;

A. -126

B. Run Time Error 

C. Garbage value

D. Compile Time Error

Option: A

Explanation

Here a variable a holds the value 130 of integer datatypes, which is then type casted to char
datatypes using pointer variable. As we know that a value 130 is exceeding the char range( -128 to
127), thus it loops through its range.

For Example

128 = -128
129 = -127
130 = -126
140 = -125

3. #include<stdio.h>

int main(){

int i = 3;

int *j;
int **k;

j = &i;

k = &j;

k++;

printf("%d ",**k);

return 0;

A.Garbage value

B. Compilation Error 

C. Run time error

D. Linker Error

Option: C

Explanation

Here k is the pointer variable which holds the address of another pointer variable j. where j is also a
pointer variable which also holds the address of another variable i. Now when the address of a
pointer variable k is incremented by 1 , then k hold some other garbage value which is not the address
of any other variable. Thus runtime error occurs.

4.#include<stdio.h>

int main(){

int i = 3;

int *j;

j = &i;

j++;

printf("%d ",*j);

return 0;

A.Linker error

B. Run time error 

C.Compilation error

D. Garbage value 
Option: D

Explanation

Here j is the pointer variable which holds the address of another variable called i. When j is
incremented, the address stored in j is incremented. As a result some garbage value will be displayed
as we had not initialized anything to the address next to the address of a variable i

5. #include<stdio.h>

#include<string.h>

int main(){

char *ptr = "hello";

char a[22];

*ptr = "world";

printf("\n%s %s",ptr, a);

return 0;

A. Linker Error

B. Run time error

C. Compilation Error

D. Garbage value

Option: C

Explanation

ptr is a pointer variable of character data type, string "world" can be set to the pointer variable ptr
only at the initializing time.

6. . What will be the output of the C program?

#include<stdio.h>

int main()

char *ptr = "2braces.com";

printf("%c\n",*&*ptr);

return 0;
}

A. Address of 2

B. Compilation Error 

C. 2

D. Run time error

Option: C

Explanation

In pointer, address operator and Multiplication operator are always cancel each other. Thus *&*ptr =
*ptr.

7. #include<stdio.h>

#include<string.h>

int main(){

register a = 1;

int far *ptr;

ptr = &a;

printf("%u",ptr);

return 0;

A. Address of a

B. Run time error 

C. Garbage value

D. Compile time error

Option: D

Explanation

"a" is a register variable which holds a value 1. It must be noted that variable a hold its value 1 in a
register but not in computer memory location thus the pointer variable ptr cannot hold the address of
a.

8. #include<stdio.h>

struct classroom
{

int students[7];

};

int main()

struct classroom cr = {2, 3, 5, 7, 11, 13};

int *ptr;

ptr = (int *)&cr;

printf("%d",*(ptr + 4));

return 0;

A. 5

B. 11

C. 13

D. 7

Option: B

Explanation

Here a pointer variable ptr holds the address of a first value (2) of an object cr, then the address of
the pointer variable is incremented by 4 and then its value is displayed .

9. #include<stdio.h>

int main(){

int a = 25, b;

ptr = &a;

ptr1 = &b;

b = 36;

printf("%d %d",*ptr, *ptr1);

return 0;

}
A. 25 45632845 

B. Run time error 

C. Compilation Error 

D. 25 36 

Option: D

Explanation

ptr holds the address of a variable A and ptr1 holds the address of a variable B . The value ofA is 25
and B is 36.

10. #include<stdio.h>

int main(){

int * ptr ;

printf("%d", sizeof(ptr));

return 0;

A. 4

B. 8

C. 2

D. compilation error

Option: A

Explanation

size of int is 4 in 32 bits and 64bit operating system.

11. #include<stdio.h>

int main()

char temp;

char arr[10] = {1, 2, 3, 4, 5, 6, 9, 8};

temp = (arr + 1)[2];

printf("%d\n", temp);
return 0;

A. 2

B. 3

C. 4

D. 5

Option: C

Explanation

Here,temp=(arr+ 1)[2]; 
Let us consider the address of first element in an array arr[10] is 2293416 then temp looks like this
temp = (2293416 + 1)[2];
Now temp =(2293420)[2];, which denotes temp = "index value of 2 from the address 2293420(value =
2)";
Now temp = 4;(address = 2293428)
Thus the program outputted 4.

12. #include<stdio.h>

int main()

int a[1][2][3] = {0};

a[0][1][2] = 5;

printf("%d",*(*(*(a+0)+1)+2));

return 0;

A. printf("%d",*(((a+0)+1)+2));

B. printf("%d",*(*(*(a+0)+1)+2));

C. printf("%d",***((a+0)+1)+2);

D. None of the above

Option: B

Explanation

Simply, this is a format for naviting to a value using the address of a first element in an array.

13. #include<stdio.h>

void fun(char**);
int main()

char *arr[] = { "bat", "cat", "fat", "hat", "mat", "pat" };

fun(arr);

return 0;

void fun(char **p)

char *t;

t = (p += sizeof(int))[-1];

printf("%s\n", t);

A. mat

B. fat

C. hat

D. cat

Option: C

Explanation

fun(arr) returns the address of first element in an array arr Let we start from the function void fun().
*t is a pointer variable which holds t = (p += sizeof(int))[-1];
ie ) t = (p = p + sizeof(int)) [-1];
t = (p = p + 4) [-1]; 
t = (p = address of bat + 4)[-1];
let us consider a address of bat is 2293416,
t = (p = 2293416 + 4)[-1];
t = (p = 2293432)[-1]
t = ("mat")[-1]; // index from "mat" 
t = "hat"; 
thus hat is outputted.

14. #include<stdio.h>

int main()

int arr[5][5][5] = {0};


printf("%d", ( &arr+1 - &arr ));

return 0;

A. 0

B. Compilation error

C. 1

D. 4

Option: C

Explanation

printf("%d", (&arr+1 - &arr)); let us consider the address of an array arr starts from 2293420
then, printf("%d", (2293420 +1 - 2293420);
printf("%d", 0 + 1);
printf("%d", 1);
Thus 1 is outputted.

15. #include<stdio.h>

int main(){

int rows = 3, colums = 4, i, j, k;

int a[3][4] = {1, 2, 3, 5, 7};

i = j = k = 00;

for(i = 0;i<rows;i++)

for(j = 0;j<colums;j++)

if(a[k][j]<k)

k = a[i][j];

printf("%d\n", k);

return 0;

A. 00

B. No output

C. 0

D. 7

Option: C
Explanation

Initially we set i = 0, j = 0, k = 0. zero be never greater than any integer values in an array a[3][4], thus
if condition fails. and 0 is outputted.

16. #include<stdio.h>

int main()

int arr[ ]={1.2, 2.4, 3.6, 4.8, 5};

int j, *ptr = arr;

for(j = 0;j<5;j++)

printf("%d ", *arr);

++ptr;

A. 2 2 2 2 2

B. 1 1 1 1 1

C. 1 2 3 4 5

D. None of the above

Option: B

Explanation

Initially array arr is assigned to a pointer variable ptr. In the for loop, ptr is incremented and not arr.
So the value 1 1 1 1 1 will be printed. as we use integer type decimal values are all exempted.

17. #include<stdio.h>

int main()

int i = 0;

printf("Hello");

char s[4] = {'\b', '\t', '\r', '\n'};

for(i = 0;i<4;i++){

printf("%c", s[i]);
}

return 0;

A. Hello

B. Compilation error

C. Hell

D. None of the above

Option: C

Explanation

Hello is printed followed by \b\t\r\n. 


i.e) Hello\b\t\r\n. 
i.e) Hell\t\r\n. 
i.e) Hell        \r\n. 
i.e) Hell\n. 
i.e) Hell is Outputted.

18. #include<stdio.h>

int main()

int i = 0;

char s[4] = {'\0', '\0', '\0', '\0'};

for(i = 0;i<4;i++)

printf("%c", s[i]);

return 0;

A. \0 \0 \0

B. \0 \0 \0 \0

C. No output

D. None of the above

Option: C
Explanation

\0 = NULL. Thus compiler prints nothing.

19. #include<stdio.h>

int main()

char s[] = {'a', 'b', 'c', '\n', 'c', '\0'};

char *p, *str, *str1;

p = &s[3];

str = p;

str1 = s;

printf("%d", ++*p + ++*str1-32);

return 0;

A. 76

B. 77

C. 78

D. 79

Option: B

Explanation

p = &s[3].
i.e) p = address of '\n';
str = p;
i.e) str = address of p;
str1 = s;
str1 = address of 'a';
printf ("%d", ++*p + ++*str1 - 32);
i.e) printf("%d", ++\n + a -32);
i.e) printf("%d", 12 + 97 -32);
i.e) printf("%d", 12 + 65);
i.e) printf("%d", 77);
Thus 77 is outputted.

20. #include<stdio.h>

int main()

{
int i = 0;

printf("Hello");

char s[4] = {'\b', '\r', '\t', '\n'};

for(i = 0;i<4;i++)

printf("%c", s[i]);

return 0;

A. Hello

B. Hell

C. No output

D. Compilation error

Option: C

Explanation

Hello is printed followed by \b\r\t\n. 


i.e) Hello\b\r\t\n. 
i.e) Hell\r\t\n. 
i.e) \t\n. 
i.e)        \n. 
i.e)     is Outputted.ie(8 space is outputted)

21. #include<stdio.h>

int main()

int arr[2] = {1, 2, 3, 4, 5};

printf("%d", arr[3]);

return 0;

A. 3

B. 4

C. Some Garbage value


D. Compilation error

Option: C

Explanation

Here the size of an array is 2, but the value inside array is exceed 2. Thus it prints garbage value for
index more than 1

22. #include<stdio.h>

int main()

int arr[5] = {1, 3, 5, 7, 11};

int *ptr, *ptr1;

ptr = &arr;

ptr1 = *ptr + 3;

printf("%d--%d", *ptr, ptr1);

A. 1--11

B. 1-7

C. 1--4

D. 1--some address

Option: C

Explanation

Here, ptr = &arr;


ptr = address of a first value in an array arr;
ptr1 = *(address of a first value in an array arr) + 3;
i.e) ptr1 = value of a first element in an array arr + 3;
i.e) ptr1 = 1 + 3;
i.e) ptr1 = 4;
printf("%d--%d", *ptr, ptr1);
printf("%d--%d", 1, 4);
Thus 1--4 is outputted.

23. #include<stdio.h>

int main()

int arr[5] = { 1, 3, 5, 7, 11 };
int *ptr;

ptr = &arr;

printf("%d", *ptr + 1);

A. 1

B. 2

C. 3

D. Runtime error

Option: B

Explanation

Here ptr = &arr; 


ptr = address of a first value in an array arr; 
*ptr = value of a first element in an array arr; 
printf("%d", *ptr + 1); 
printf("%d", 1 + 1); 
Thus 2 is outputted.

24.#include <stdio.h>

int main()

    static int var[5];

    int count=0;

     

    var[++count]=++count;

    for(count=0;count<5;count++)

        printf("%d ",var[count]);

     

    return 0;

A.0 1 0 0 0

    B.0 2 0 0 0
   C.0 0 2 0 0

   D.0 0 0 0 0

Option C

25)

#include "stdio.h"

int main()

    char a[] = { 'A', 'B', 'C', 'D' };

    char* ppp = &a[0];

    *ppp++; // Line 1

    printf("%c %c ", *++ppp, --*ppp); // Line 2

OPTIONS: 
a)C B
b)B A
c)B C
d)C A

OUTPUT: (d) C A

Explanation: 
Line 1 : Now, ppp points to next memory location i.e., index 1 of the character array.
Line 2 : Firstly, –*ppp= –(*ppp) is executed and hence the value ‘B’ (which is in the index 1 position of
the char[] array) gets decremented by 1(i.e., it becomes ‘A’)and it is sent for printing. Then *++ppp=
*(++ppp) is executed which initially increments the pointer to the next element of the array and prints
the value in that index number 2 which is ‘C’. Although –*ppp is executed first compared to *++ppp,
the display will be shown in the order as we mentioned in the printf() function in line 2. Hence we get
output as C A.

1.#include<stdio.h>

#include<conio.h>

int main()

{printf("%c\n",7["pointerofc"] );

getch();

return 0;
}

o/p:o

2.#include<stdio.h>

int main(){

while (!printf( "Geeks for Geeks" ))

{}

3. // CPP program to print

// ; without using ;

// using if statement

#include <stdio.h>

int main()

// ASCII value of semicolon = 59

if (printf("%c\n", 59))

if (putchar(59))

return 0;

4. #include "stdio.h"

int main()

void *pVoid;

pVoid = (void*)0;

printf("%lu",sizeof(pVoid));

return 0;

}
Pick the best statement for the above C program snippet.
(A) Assigning (void *)0 to pVoid isn’t correct because memory hasn’t been allocated. That’s why no
compile error but it’ll result in run time error.
(B) Assigning (void *)0 to pVoid isn’t correct because a hard coded value (here zero i.e. 0) can’t
assigned to any pointer. That’s why it’ll result in compile error.
(C) No compile issue and no run time issue. And the size of the void pointer i.e. pVoid would equal to
size of int.
(D) sizeof() operator isn’t defined for a pointer of void type.

5. Assume int is 4 bytes, char is 1 byte and float is 4 bytes. Also, assume that pointer size is 4 bytes
(i.e. typical case)

char *pChar;

int *pInt;

float *pFloat;

sizeof(pChar);

sizeof(pInt);

sizeof(pFloat);

a.444

b.144

c.148

d.none

ans:a

6. #include "stdio.h"

void fun(int n)

int idx;

int arr1[n] = {0};

int arr2[n];
for (idx=0; idx<n; idx++)

arr2[idx] = 0;

int main()

fun(4);

return 0;

Definition of both arr1 and arr2 is incorrect because variable is used to specify the size of array. That’s
why compile error.
(B) Apart from definition of arr1 arr2, initialization of arr1 is also incorrect. arr1 can’t be initialized due
to its size being specified as variable. That’s why compile error.
(C) Initialization of arr1 is incorrect. arr1 can’t be initialized due to its size being specified as variable.
That’s why compile error.
(D) No compile error. The program would define and initializes both arrays to ZERO.

Answer: (C) 

7. Which of the followings is correct for a function definition along with storage-class specifier in C
language?
(A) int fun(auto int arg)
(B) int fun(static int arg)
(C) int fun(register int arg)
(D) int fun(extern int arg)
(E) All of the above are correct.

Answer: (C) 

8. Suppose a, b, c and d are int variables. For ternary operator in C ( ? : ), pick the best statement.

(A) a>b ? : ; is valid statement i.e. 2nd and 3rd operands can be empty and they are implicitly replaced
with non-zero value at run-time.
(B) a>b ? c=10 : d=10; is valid statement. Based on the value of a and b, either c or d gets assigned the
value of 10.
(C) a>b ? (c=10,d=20) : (c=20,d=10); is valid statement. Based on the value of a and b, either
c=10,d=20 gets executed or c=20,d=10 gets executed.
(D) All of the above are valid statements for ternary operator.

Answer: (C) 

9. int (*p)[5];

It will result in compile error because there shouldn’t be any parenthesis i.e. “int *p[5]” is valid.
(B) p is a pointer to 5 integers.
(C) p is a pointer to integer array.
(D) p is an array of 5 pointers to integers.
(E) p is a pointer to an array of 5 integers

Answer: (E) 

10. float x = 2.17;

double y = 2.17;

long double z = 2.17;

Which of the following is correct way for printing these variables via printf.
(A) printf(“%f %lf %Lf”,x,y,z);
(B) printf(“%f %f %f”,x,y,z);
(C) printf(“%f %ff %fff”,x,y,z);
(D) printf(“%f %lf %llf”,x,y,z);

Answer: (A) 

1)

# include <stdio.h>

void fun(int *ptr)

   *ptr = 30;
}

int main()

 int y = 20;

 fun(&y);

 printf("%d", y);

 return 0;

Ans:30

2)

#include <stdio.h>

int main()

   int *ptr;

   int x;

   ptr = &x;

   *ptr = 0;

   printf(" x = %dn", x);

   printf(" *ptr = %dn", *ptr);

   *ptr += 5;

   printf(" x  = %dn", x);

   printf(" *ptr = %dn", *ptr);

   (*ptr)++;

   printf(" x = %dn", x);

   printf(" *ptr = %dn", *ptr);

   return 0;

Ans:x = 0

*ptr = 0
x=5

*ptr = 5

x=6

*ptr = 6

3)

#include<stdio.h>

int main()

   int arr[] = {10, 20, 30, 40, 50, 60};

   int *ptr1 = arr;

   int *ptr2 = arr + 5;

   printf("Number of elements between two pointer are: %d.",

                               (ptr2 - ptr1));

   printf("Number of bytes between two pointers are: %d",  

                             (char*)ptr2 - (char*) ptr1);

   return 0;

Ans:Number of elements between two pointer are: 5. Number of bytes between two pointers are: 20

4)

#include <stdio.h>

int main()

   float arr[5] = {12.5, 10.0, 13.5, 90.5, 0.5};

   float *ptr1 = &arr[0];

   float *ptr2 = ptr1 + 3;

   printf("%f ", *ptr2);

   printf("%d", ptr2 - ptr1);

  return 0;

}
Ans:90.500000 3

5)

#include<stdio.h>

int main()

  int a;

  char *x;

  x = (char *) &a;

  a = 512;

  x[0] = 1;

  x[1] = 2;

  printf("%dn",a);   

  return 0;

Ans:Machine dependent

6)

int main()

char *ptr = "GeeksQuiz";

printf("%cn", *&*&*ptr);

return 0;

Ans: G

7)

#include<stdio.h>

void fun(int arr[])

 int i;

 int arr_size = sizeof(arr)/sizeof(arr[0]);


 for (i = 0; i < arr_size; i++)

     printf("%d ", arr[i]);

int main()

 int i;

 int arr[4] = {10, 20 ,30, 40};

 fun(arr);

 return 0;

Ans:Machine Dependent

8)

#include<stdio.h>

void f(int *p, int *q)

 p = q;

 *p = 2;

int i = 0, j = 1;

int main()

 f(&i, &j);

 printf("%d %d n", i, j);

 getchar();

 return 0;

Ans: 0 2

9)

int f(int x, int *py, int **ppz)


{

 int y, z;

 **ppz += 1;

  z = **ppz;

 *py += 2;

  y = *py;

  x += 3;

  return x + y + z;

  

void main()

  int c, *b, **a;

  c = 4;

  b = &c;

  a = &b;

  printf("%d ", f(c, b, a));

  return 0;

ans: 19

10)

#include<stdio.h>

int main()

   int a = 12;

   void *ptr = (int *)&a;

   printf("%d", *ptr);

   getchar();

   return 0;
}

ans:Compiler error

11)

#include<stdio.h>

void swap (char *x, char *y)

   char *t = x;

   x = y;

   y = t;

int main()

   char *x = "geeksquiz";

   char *y = "geeksforgeeks";

   char *t;

   swap(x, y);

   printf("(%s, %s)", x, y);

   t = x;

   x = y;

   y = t;

   printf("n(%s, %s)", x, y);

   return 0;

Ans:(geeksquiz, geeksforgeeks)

(geeksforgeeks, geeksquiz)

12)

#include <stdio.h>

int main()

{
   int arr[] = {1, 2, 3, 4, 5};

   int *p = arr;

   ++*p;

   p += 2;

   printf("%d", *p);

   return 0;

Ans: 3

13)

#include <stdio.h>

void f(char**);

int main()

   char *argv[] = { "ab", "cd", "ef", "gh", "ij", "kl" };

   f(argv);

   return 0;

void f(char **p)

   char *t;

   t = (p += sizeof(int))[-1];

   printf("%s\n", t);

ans: gh

14)

What does the following C-statement declare? [1 mark]

int ( * f) (int * ) ;

ans:A pointer to a function that takes an integer pointer as argument and returns an integer.

15)
#include <stdio.h>

#define print(x) printf("%d ", x)

int x;

void Q(int z)

   z += x;

   print(z);

void P(int *y)

   int x = *y + 2;

   Q(x);

   *y = x - 1;

   print(x);

main(void)

   x = 5;

   P(&x);

   print(x);

ans: 12 7 6

16)

char *pChar;

int *pInt;

float *pFloat;

sizeof(pChar);

sizeof(pInt);

sizeof(pFloat);
ans: 4 4 4

17)

In the below statement, ptr1 and ptr2 are uninitialized pointers to int i.e. they are pointing to some
random address that may or may not be valid address.

int* ptr1, ptr2;

ans:false

18)

#include <stdio.h>

int main()

int var;  /*Suppose address of var is 2000 */

void *ptr = &var;

*ptr = 5;

printf("var=%d and *ptr=%d",var,*ptr);

             

return 0;

ans:Compile error

19)#include<stdio.h>

void mystery(int *ptra, int *ptrb)

  int *temp;

  temp = ptrb;

  ptrb = ptra;

  ptra = temp;

int main()

   int a=2016, b=0, c=4, d=42;


   mystery(&a, &b);

   if (a < c)

      mystery(&c, &a);

   mystery(&a, &d);

   printf("%dn", a);

ans: 2016

20)

void f(int* p, int m)

   m = m + 5;

   *p = *p + m;

   return;

void main()

   int i=5, j=10;

   f(&i, j);

   printf("%d", i+j);

ans:30

21)

int main()

   int array[5][5];

   printf("%d",( (array == *array) && (*array == array[0]) ));

   return 0;    

ans:1
22)

int main()

  int a = 300;    

  char *b = (char *)&a;

  *++b = 2;

  printf("%d ",a);

  return 0;

ans:556

23)

void printxy(int x, int y)

   int *ptr;

   x = 0;

   ptr = &x;

   y = *ptr;

   *ptr = 1;

   printf("%d,%d", x, y);

ans:1,0

24)

# include <stdio.h>

void fun(int x)

   x = 30;

int main()

{
 int y = 20;

 fun(y);

 printf("%d", y);

 return 0;

ans:20

25)

Faster access to non-local variables is achieved using an array of pointers to activation records, called
a

ans:activation tree

1.What will be the output of following program ? (for 32 bits compiler)

#include <stdio.h>

int main()

   int MAX=10;

   int array[MAX];

   printf("size of array is = %d",sizeof(array);

   return 0;

1.   size of array is = 20

2.   size of array is = 40

3.   size of array is = 4

4.   Error

ans:2

2.What will be the output of following program ?


#include <stdio.h>

#define MAX 10

int main()

{   int array[MAX]={1,2,3},tally;

   for(tally=0;tally< sizeof(array)/sizeof(int);tally+=1)

       printf("%d ",*(tally+array));

   return 0;

 1.  Error

 2.  1 3 4 5 6 7 8 9 10 11

 3.  1 2 3 0 0 0 0 0 0 0

 4.  0 0 0 0 0 0 0 0 0 0

Ans:3

You can also access the array elements using *(counter_variable+array_name).

3.What will be the output of following program ?

#include <stdio.h>

int main()

{   static int array[]={10,20,30,40,50};

   printf("%d...%d",*array,*(array+3)* *array);

   return 0;

 1. Error

 2.  10...40

 3.  10...300

 4.  10....400
Ans:4

Explanation:

In expression printf("%d...%d",*array,*(array+3)* *array);, *array is 10, *(array+3) is 40.

4.What will be the output of following program ?

#include <stdio.h>

int main()

{   static int x[]={'A','B','C','D','E'},tally;

   for(tally=0;tally< sizeof(x)/sizeof(int) ; tally+=1)

       printf("%c,%c,%c\n",*(x+tally)+1,x[tally]+1,*(tally+x)+1);

   return 0;

 1.  Error

 2.  A,A,A

     B,B,B

     C,C,C

     D,D,D

     E,E,E

 3.  B,B,B

     C,C,C

     D,D,D

     E,E,E

     F,F,F

 
 4.  E,E,E

     D,D,D

     C,C,C

     B,B,B

    A,A,A

Ans: 3

B,B,B

C,C,C

D,D,D

E,E,E

F,F,F

5.Consider an array A[20, 10], assume 4 words per memory cell and the base address of array A is
100. What is the address of A[11, 5] ? Assume row major storage.

1. 560

2. 565

3. 570

4. 575

Ans:1

6.Which of the following is an illegal array definition?

1. Type COLONGE : (LIME, PINE, MUSK, MENTHOL); var a : array [COLONGE] of REAL;

2. var a : array [REAL] of REAL;

3. var a : array [‘A’…’Z’] of REAL;

4. var a : array [BOOLEAN] of REAL;


Ans:2

7.A three dimensional array in ‘C’ is declared as int A[x][y][z]. Here, the address of an item at the
location A[p][q][r] can be computed as follows (where w is the word length of an integer):

1. &A[0][0][0] + w(y * z * q + z * p + r)

2. &A[0][0][0] + w(y * z * p + z*q + r)

3. &A[0][0][0] + w(x * y * p + z * q+ r)

4. &A[0][0][0] + w(x * y * q + z * p + r)

Ans:2

8.What would be the equivalent pointer expression for referring the array element a[i][j][k][l]

 1. ((((a+i)+j)+k)+l)

 2. *(*(*(*(a+i)+j)+k)+l)

 3. (((a+i)+j)+k+l)

 4. ((a+i)+j+k+l)

Ans:2

9.Which of the following operations is not O(1) for an array of sorted data. You may assume that array
elements are distinct.

1. Find the ith largest element

2. Delete an element

3. Find the ith smallest element

4. All of the above


Ans:2

10.What is the output of following program?

# include <stdio.h>

void fun(int x)

   x = 30;

int main()

 int y = 20;

 fun(y);

 printf("%d", y);

 return 0;

1. 30

2. 20

3. Compiler Error

4. Runtime Error

Ans:2

11.What is the output of above program?

#include<stdio.h>  

int main()  


  int a;  

  char *x;  

  x = (char *) &a;  

  a = 512;  

  x[0] = 1;  

  x[1] = 2;  

  printf("%d\n",a);    

  return 0;  

1. Machine dependent

2. 513

3. 258

4. Compiler Error

ans:1

12.What is (void*)0?

1. Representation of NULL pointer

2. Representation of void pointer

3. Error

4. None of above

ans:1

13.In which header file is the NULL macro defined?

1. stdio.h

2. stddef.h

3. stdio.h and stddef.h

4. math.h
Ans:3

The macro "NULL" is defined in locale.h, stddef.h, stdio.h, stdlib.h, string.h, time.h, and wchar.h.

14.How many bytes are occupied by near, far and huge pointers (DOS)?

1. near=2 far=4 huge=4

2. near=4 far=8 huge=8

3. near=2 far=4 huge=8

4. near=4 far=4 huge=8

Ans:1

near=2, far=4 and huge=4 pointers exist only under DOS. Under windows and Linux every pointers is 4
bytes long

15.If a variable is a pointer to a structure, then which of the following operator is used to access data
members of the structure through the pointer variable?

1. .

2. &

3. *

4. ->

Ans:4

16.The operator used to get value at address stored in a pointer variable is

1. *

2. &

3. &&

4. ||
Ans:1

17.Point out the compile time error in the program given below.

#include<stdio.h>

int main()

   int *x;

   *x=100;

   return 0;

1. Error: invalid assignment for x

2. Error: suspicious pointer conversion

3. No error

4. None of above

Ans:3

Explanation:

   While reading the code there is no error, but upon running the program having an unitialised
variable can cause the program to crash (Null pointer assignment).

18.What will happen if in a C program you assign a value to an array element whose subscript exceeds
the size of array?

1. The element will be set to 0.

2. The compiler would report an error.

3. The program may crash if some important data gets overwritten.

4. The array size would appropriately grow.


Ans:3

Explanation:

   If the index of the array size is exceeded, the program will crash. Hence "option c" is the correct
answer. But the modern compilers will take care of this kind of errors.

19.What does the following declaration mean?

int (*ptr)[10];

1. ptr is array of pointers to 10 integers

2. ptr is a pointer to an array of 10 integers

3. ptr is an array of 10 integers

4.ptr is an pointer to array

Ans:2

20.In C, if you pass an array as an argument to a function, what actually gets passed?

1.Value of elements in array

2. First element of the array

3. Base address of the array

4. Address of the last element of array

Ans:3

21.Which of the following statements are correct about 6 used in the program?

int num[6];

num[6]=21;
1. In the first statement 6 specifies a particular element, whereas in the second statement it specifies
a type.

2. In the first statement 6 specifies a array size, whereas in the second statement it specifies a
particular element of array.

3. In the first statement 6 specifies a particular element, whereas in the second statement it specifies
a array size.

4.In both the statement 6 specifies array size.

Ans:2

Explanation:

  The statement 'B' is correct, because int num[6]; specifies the size of array and num[6]=21;
designates the particular element(7th element) of the array.

22.Which of the following statements are correct about an array?

1: The array int num[26]; can store 26 elements.

2: The expression num[1] designates the very first element in the array.

3: It is necessary to initialize the array at the time of declaration.

4: The declaration num[SIZE] is allowed if SIZE is a macro.

A. 1

B. 1,4

C. 2,3

D. 2,4

Ans:  B

Explanation:

1. The array int num[26]; can store 26 elements. This statement is true.
2. The expression num[1] designates the very first element in the array. This statement is false,
because it designates the second element of the array.

3. It is necessary to initialize the array at the time of declaration. This statement is false.

4. The declaration num[SIZE] is allowed if SIZE is a macro. This statement is true, because the MACRO
just replaces the symbol SIZE with given value.

Hence the statements '1' and '4' are correct statements.

23.A pointer to a block of memory is effectively same as an array

1. True

2. False

Ans:1

Explanation:

   Yes, It is possible to allocate a block of memory (of arbitrary size) at run-time, using the standard
library's malloc function, and treat it as an array.

24.What is (void*)0?

1. Representation of NULL pointer

2. Representation of void pointer

3. Error

4. None of above

Ans:1

25.What will be the output of the following C code?


   #include <stdio.h>

   int main()

   {

       char *a[2] = {"hello", "hi"};

       printf("%s", *(a + 1));

       return 0;

   }

1. hello

2. ello

3. hi

4. ello hi

ans:3

26. What will be the output of the following C code?

   #include <stdio.h>

   int main()

   {

       char a[2][6] = {"hello", "hi"};

       printf("%d", sizeof(a));

       return 0;

   }

1.  9

2. 12

3. 8
4. 10

ans:2

27.What is the advantage of a multidimensional array over pointer array?

1.  Predefined size

2. Input can be taken from user

3. Faster Access

4. All of the mentioned

ans:4

28.Comment on the following two operations.

   int *a[] = {{1, 2, 3}, {1, 2, 3, 4}}; //- 1

   int b[4][4] = {{1, 2, 3}, {1, 2, 3, 4}};//- 2

1. 1 will work, 2 will not

2. 1 and 2, both will work

3. 1 won’t work, 2 will work

4. Neither of them will work

ans:3

29.Comment on the following two operations.

   int *a[] = {{1, 2, 3}, {1, 2, 3, 4}}; //- 1

   int b[][] = {{1, 2, 3}, {1, 2, 3, 4}}; //- 2


1. 1 works, 2 doesn’t

2. 2 works, 1 doesn’t

3. Both of them work

4. Neither of them work

ans:4

30.Which of the following can never be sent by call-by-value?

1. Variable

2. Array

3. Structures

4. Both Array and Structures

ans:2

31. Which of the following is the correct syntax to send an array as a parameter to function?

a) func(&array);

b) func(#array);

c) func(*array);

d) func(array[size]);

ans: a

32.What will be the output of the following C code?

   #include <stdio.h>
   int main()

   {

       int i = 10;

       int *const p = &i;

       foo(&p);

       printf("%d\n", *p);

   }

   void foo(int **p)

   {

       int j = 11;

       *p = &j;

       printf("%d\n", **p);

   }

a) 11 11

b) Undefined behaviour

c) Compile time error

d) Segmentation fault/code-crash

ans: a

33. What will be the output of the following C code?

   #include <stdio.h>

   int main()

   {

       int i = 97, *p = &i;

       foo(&i);

       printf("%d ", *p);


   }

   void foo(int *p)

   {

       int j = 2;

       p = &j;

       printf("%d ", *p);

   }

a) 2 97

b) 2 2

c) Compile time error

d) Segmentation fault/code crash

ans: a

34.What will be the output of the following C code?

   #include <stdio.h>

   void foo(int*);

   int main()

   {

       int i = 10;

       foo((&i)++);

   }

   void foo(int *p)

   {

       printf("%d\n", *p);

   }
a) 10

b) Some garbage value

c) Compile time error

d) Segmentation fault/code crash

ans: c

35.What will be the output of the following C code?

   #include <stdio.h>

   struct p

   {

       int x;

       char y;

   };

   int main()

   {

       struct p p1[] = {1, 92, 3, 94, 5, 96};

       struct p *ptr1 = p1;

       int x = (sizeof(p1) / 3);

       if (x == sizeof(int) + sizeof(char))

           printf("%d\n", ptr1->x);

       else

           printf("falsen");

   }

a) Compile time error

b) 1

c) Undefined behaviour
d) false

ans: d

36.What will be the output of the following C code?

   #include <stdio.h>

   struct p

   {

       int x;

       char y;

   };

   typedef struct p* q*;

   int main()

   {

       struct p p1[] = {1, 92, 3, 94, 5, 96};

       q ptr1 = p1;

       printf("%d\n", ptr1->x);

   }

a) Compile time error

b) 1

c) Undefined behaviour

d) Segmentation fault

ans: d

37.What will be the output of the following C code?


   #include <stdio.h>

   void main()

   {

       int k = 5;

       int *p = &k;

       int **m = &p;

       printf("%d%d%d\n", k, *p, **m);

   }

a) 5 5 5

b) 5 5 junk value

c) 5 junk junk

d) Run time error

ans: a

38.Which is true for a, if a is defined as “int a[10][20];”?

a) a is true two-dimensional array

b) 200 int-sized locations have been set aside

c) The conventional rectangular subscript calculation 20 * row + col is used to find the element a[row,
col].

d) All of the mentioned

ans: d

39. Which is true for b, if b is defined as “int *b[10];”?

a) The definition only allocates 10 pointers and does not initialize them
b) Initialization must be done explicitly

c) The definition only allocates 10 pointers and does not initialize them & Initialization must be done
explicitly

d) Error

ans: c

40.What will be the output of the following C code?

   #include <stdio.h>

   void main()

   {

       char a[10][5] = {"hi", "hello", "fellows"};

       printf("%s", a[2]);

   }

a) fellows

b) fellow

c) fello

d) fell

ans: c

41. What will be the output of the following C code?

   #include <stdio.h>

   int main()

   {

       char a[1][5] = {"hello"};


       printf("%s", a[0]);

       return 0;

   }

a) Compile time error

b) hello

c) Undefined behaviour

d) hellon

ans: c

42. Which of the following statements are true?

   P. Pointer to Array

   Q. Multi-dimensional array

a) P are static, Q are static

b) P are static, Q are dynamic

c) P are dynamic, Q are static

d) P are dynamic, Q are dynamic

ans: c

43.What will be the output of the following C code?

   #include <stdio.h>

   struct point

   {

       int x;
       int y;

   };

   void foo(struct point*);

   int main()

   {

       struct point p1[]  = {1, 2, 3, 4};

       foo(p1);

   }

   void foo(struct point p[])

   {

       printf("%d\n", p[1].x);

   }

a) Compile time error

b) 3

c) 2

d) 1

ans: b

44.What will be the output of the following C code?

   #include <stdio.h>

   struct student

   {

       char *c;

   };

   void main()

   {
       struct student s[2];

       printf("%d", sizeof(s));

   }

a) 2

b) 4

c) 16

d) 8

ans: d

45.What will be the output of the following C code?

   #include <stdio.h>

   int main()

   {

       int i = 0, j = 1;

       int *a[] = {&i, &j};

       printf("%d", (*a)[0]);

       return 0;

   }

a) Compile time error

b) Undefined behaviour

c) 0

d) Some garbage value

ans: c
46.Pointer of stack, is always set to

a)First position of array

b)Second position of array

c)Third position of array

d)Forth position of array

ans : a

47.To set array[i] to 0, we must first get its address, start by multiplying i with

a)0

b)1

c)2

d)4

ans: d

48.What do the following declaration signify?

char **argv;

a) argv is a pointer to pointer.

b) argv is a pointer to a char pointer.

c) argv is a function pointer.

d) argv is a member of function pointer.

ans: b
49. What do the following declaration signify?

int (*pf)();

a) pf is a pointer to function.

b) pf is a function pointer.

c) pf is a pointer to a function which return int

d) pf is a function of pointer variable.

ans: c

50.What will be the output of the C program?

#include<stdio.h>

int main(){

char array[5] = "Knot", *ptr, i, *ptr1;

ptr = &array[1];

ptr1 = ptr + 3;

*ptr1 = 101;

for(i = 0; i < 4;i++)

printf("%c", *ptr++);

return 0;

a) not

b) Knot

c) note

d)garbage value
ans: c

Explanation:

In the above program, we assigned the starting value of pointer variable is with the address of second
element in an array i.e) Knot. Then we append the value 101 i.e)'e' to the ptr variable. Thus it prints
note

1)

#include<stdio.h>

#include<conio.h>

int main()

int num , *ptr1 ,*ptr2 ;

ptr1 = &num ;

ptr2 = ptr1 + 2 ;

clrscr();

printf("%d",ptr2 - ptr1);

getch();

return(0);

Output :

2) #include<stdio.h>

int main()

int a=0, b=1, c=3;

*((a) ?&b :&a) = a ? b : c;

printf("%d, %d, %d\n", a, b, c);

return 0;
}

o/p:3 1 3

3) void main()

int c[ ]={2.8,3.4,4,6.7,5};

int j,*p=c,*q=c;

for(j=0;j<5;j++)

printf (" %d ",*c);

++q;

for(j=0;j<5;j++)

printf(" %d ",*p);

++p;

o/p:

22222

23465

4) #include<stdio.h>

#include <conio.h>

void main()

char s[]={'a','b','c','\n','c','\0'};

char *p,*str,*str1;

p=&s[3];

str=p;

str1=s;
clrscr();

printf("%d",++*p + ++*str1-32);

getch();

o/p:77

5)

#include<stdio.h>

#include <conio.h>

void main()

int a[2][2][2] = { {10,2,3,4}, {5,6,7,8} };

int *p,*q;

p=&a[2][2][2];

*q=***a;

clrscr();

printf("%d----%d",*p,*q);

getch();

o/p:0----10

6) #include <stdio.h>

#include <conio.h>

void main( )

static int a[ ] = {0,1,2,3,4};

int *p[ ] = {a,a+1,a+2,a+3,a+4};

int **ptr = p;

ptr++;

clrscr();

printf(“\n %d %d %d”, ptr-p, *ptr-a, **ptr);


*ptr++;

printf(“\n %d %d %d”, ptr-p, *ptr-a, **ptr);

*++ptr;

printf(“\n %d %d %d”, ptr-p, *ptr-a, **ptr);

++*ptr;

printf(“\n %d %d %d”, ptr-p, *ptr-a, **ptr);

getch();

o/p:1 1 1

      2 2 2

    3 3 3

   3 4 4

7)

#include <stdio.h>

#include <conio.h>

void main( )

static char *s[ ] = {“black”, “white”, “yellow”, “violet”};

char **ptr[ ] = {s+3, s+2, s+1, s}, ***p;

p = ptr;

**++p;

clrscr();

printf(“%s”,*--*++p + 3);

getch();

o/p:ck

8)

#include <stdio.h>

#include <conio.h>
void main()

int i = 257;

int *iPtr = &i;

clrscr();

printf("%d %d", *((char*)iPtr), *((char*)iPtr+1) );

getch();

o/p:1 1

9)

#include<stdio.h>

#include <conio.h>

int main()

int arr[2][2][2] = {10, 2, 3, 4, 5, 6, 7, 8};

int *p, *q;

p = &arr[1][1][1];

q = (int*) arr;

clrscr();

printf("%d, %d\n", *p, *q);

getch();

return 0;

o/p:8,10

10)

#include<stdio.h>

#include <conio.h>

int main()

{
int a[3][4] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 };

clrscr();

printf("%u, %u, %u\n", a[0]+1, *(a[0]+1), *(*(a+0)+1));

getch();

return 0;

Output :

1006, 2, 2

11)

#include <stdio.h>

   int main()

   {

       int ary[4] = {1, 2, 3, 4};

       int *p = ary + 3;

       printf("%d\n", p[-2]);
   }

o/p:

12) #include<stdio.h>

int main()

int x = 20, *y, *z;

// Assume address of x is 500 and

// integer is 4 byte size

y = &x;

z = y;

*y++;

*z++;

x++;

printf("x = %d, y = %d, z = %d \n", x, y, z);

return 0;

o/p: x=21 y=504 z=504

13) #include "stdio.h"

int main()

char a[] = { 'A', 'B', 'C', 'D' };

char* ppp = &a[0];

*ppp++; // Line 1

printf("%c %c ", *++ppp, --*ppp); // Line 2

}
o/p:C A

14) main()

int i=5;

printf("%d%d%d%d%d%d",i++,i--,++i,--i,i);

Answer:

45545

15)

#include<stdio.h>

#include<conio.h>

void main()

int const * p=5;

printf("%d",++(*p)); Line 6

Output :

Compiler error: Cannot modify a constant value.

16)

void main()

char s[ ]="man";

int i;

for(i=0;s[ i];i++)

printf("\n%c%c%c%c",s[i],*(s+i),*(i+s),i[s]);

Output :
mmmm

aaaa

nnnn

17)

#include <stdio.h>

#include <conio.h>

void main()

void *v;

int integer=2;

int *i=&integer;

v=i;

printf("%d",(int*)*v);

o/p:error

18)

void main()

int a[10];

clrscr();

printf("%d",*a+1-*a+3);

getch();

Output :

19)

#include <stdio.h>

#include <conio.h>

void main()
{

char p[ ]="%d\n";

p[1] = 'c';

clrscr();

printf(p,65);

getch();

Output :

20)

#include <stdio.h>

#include <conio.h>

void main()

int a=2,*f1,*f2;

f1 = f2 = &a;

*f2 += *f2 += a += 2.5;

clrscr();

printf("\n%d %d %d",a,*f1,*f2);

getch();

Output :

16 16 16

21)

#include <stdio.h>

#include <conio.h>

void main()

int i=300;
char *ptr = &i;

*++ptr=2;

clrscr();

printf("%d",i);

getch();

Output :

556

22)

#include <stdio.h>

#include <conio.h

void main()

char * str = "hello";

char * ptr = str;

char least = 127;

while (*ptr++)

least = *ptr;

clrscr();

printf("%d",least);

getch();

Output :

23)

#include <stdio.h>

#include <conio.h>
void main()

int i=10, j=2;

int *ip= &i, *jp = &j;

int k = *ip/*jp; Error

clrscr();

printf(“%d”,k);

getch();

Output :

Error

24)

#include <stdio.h>

#include <conio.h>

void main(){

int *ptr;

ptr = (int *) 0x400;

clrscr();

printf("%d",*ptr);

getch();

Output : 0

25)

#include <stdio.h>

#include <conio.h>

void main()

int a=10,*j;
void *k;

j=k=&a;

j++;

k++; Line 10

printf("\n %u %u ",j,k);

Output :

error

QUESTIONS

1.What will be the output

  #include<stdio.h>

  int main()

  {

   int a[] = { 1, 2, 3, 4, 5} ;

   int *ptr;

   ptr = a;

   printf(" %d ", *( ptr + 1) );

   return 0;

  }

  output

   2

2.What will be a output


  

#include<stdio.h>

int main()

   int x = 20, *y, *z;

     

   // Assume address of x is 500 and  

   // integer is 4 byte size  

   y = &x;  

   z = y;

   *y++;  

   *z++;

   x++;

   printf("x = %d, y = %d, z = %d \n", x, y, z);

   return 0;

Output:

x=21 y=504 z=504

3. What is (void*)0?

     A. Representation of NULL pointer

     B. Representation of void pointer

     C. Error

     D. None of above

 ANS:C
4.What would be the equivalent pointer expression for referring the array element a[i][j][k][l]

   A. ((((a+i)+j)+k)+l)

   B. *(*(*(*(a+i)+j)+k)+l)

   C. (((a+i)+j)+k+l)

   D. ((a+i)+j+k+l)

 ANS:B

5.The operator used to get value at address stored in a pointer variable is

   A. *

   B. &

   C. &&

   D. ||

 ANS:A

6.Point out the compile time error in the program given below.

#include<stdio.h>

int main()

   int *x;

   *x=100;

   return 0;

   A. Error: invalid assignment for x

   B. Error: suspicious pointer conversion

   C. No error

   D. None of above


  ANS:C

7.Point out the error in the program

#include<stdio.h>

int main()

   int a[] = {10, 20, 30, 40, 50};

   int j;

   for(j=0; j<5; j++)

   {

       printf("%d\n", a);

       a++;

   }

   return 0;

   A. Error: Declaration syntax

   B. Error: Expression syntax

   C. Error: LValue required

   D. Error: Rvalue required

  ANS:C

8.#include<stdio.h>

int main()

   static char *s[] = {"black", "white", "pink", "violet"};


   char **ptr[] = {s+3, s+2, s+1, s}, ***p;

   p = ptr;

   ++p;

   printf("%s", **p+1);

   return 0;

   A. ink

   B. ack

   C. ite

   D. let

  ANS:A

9.What will be the output of the program If the integer is 4bytes long?

#include<stdio.h>

int main()

   int ***r, **q, *p, i=8;

   p = &i;

   q = &p;

   r = &q;

   printf("%d, %d, %d\n", *p, **q, ***r);

   return 0;

   A. 8, 8, 8

   B. 4000, 4002, 4004


   C. 4000, 4004, 4008

   D. 4000, 4008, 4016

 ANS:A

10.A pointer is

   A. A keyword used to create variables

   B. A variable that stores address of an instruction

   C. A variable that stores address of other variable

   D. All of the above

 ANS:C

11.Are the expression *ptr++ and ++*ptr are same?

   A. True

   B. False

 ANS:B

12.Will the program compile?

#include<stdio.h>

int main()

   char str[5] = "IndiaBIX";

   return 0;

  A. True

  B. False

ANS:A
13.The following program reports an error on compilation.

#include<stdio.h>

int main()

   float i=10, *j;

   void *k;

   k=&i;

   j=k;

   printf("%f\n", *j);

   return 0;

  A. True

  B. False

 ANS:B

14.What will happen if in a C program you assign a value to an array element whose subscript exceeds
the size of array?

A. The element will be set to 0.

B. The compiler would report an error.

C. The program may crash if some important data gets overwritten.

D. The array size would appropriately grow.

  ANS:C

  

15.What does the following declaration mean?

int (*ptr)[10];
A. ptr is array of pointers to 10 integers

B. ptr is a pointer to an array of 10 integers

C. ptr is an array of 10 integers

D. ptr is an pointer to array

  ANS:B

  

16.In C, if you pass an array as an argument to a function, what actually gets passed?

A. Value of elements in array

B. First element of the array

C. Base address of the array

D. Address of the last element of array

  ANS:C

  

17.What will be the output of the program ?

#include<stdio.h>

int main()

   int a[5] = {5, 1, 15, 20, 25};

   int i, j, m;

   i = ++a[1];

   j = a[1]++;

   m = a[i++];

   printf("%d, %d, %d", i, j, m);

   return 0;

A. 2, 1, 15
B. 1, 2, 5

C. 3, 2, 15

D. 2, 3, 20

  ANS:C

  

18.What will be the output of the program ?

#include<stdio.h>

int main()

   static int a[2][2] = {1, 2, 3, 4};

   int i, j;

   static int *p[] = {(int*)a, (int*)a+1, (int*)a+2};

   for(i=0; i<2; i++)

   {

       for(j=0; j<2; j++)

       {

           printf("%d, %d, %d, %d\n", *(*(p+i)+j), *(*(j+p)+i),

                                   *(*(i+p)+j), *(*(p+j)+i));

       }

   }

   return 0;

A. 1, 1, 1, 1

2, 3, 2, 3

3, 2, 3, 2

4, 4, 4, 4

B. 1, 2, 1, 2
2, 3, 2, 3

3, 4, 3, 4

4, 2, 4, 2

C. 1, 1, 1, 1

2, 2, 2, 2

2, 2, 2, 2

3, 3, 3, 3

D. 1, 2, 3, 4

2, 3, 4, 1

3, 4, 1, 2

4, 1, 2, 3

    ANS:C

19.What will be the output of the program ?

#include<stdio.h>

void fun(int **p);

int main()

   int a[3][4] = {1, 2, 3, 4, 4, 3, 2, 8, 7, 8, 9, 0};

   int *ptr;

   ptr = &a[0][0];

   fun(&ptr);

   return 0;

void fun(int **p)

   printf("%d\n", **p);
}

A. 1

B. 2

C. 3

D. 4

  ANS:A

20.What will be the output of the program if the array begins 1200 in memory?

#include<stdio.h>

int main()

   int arr[]={2, 3, 4, 1, 6};

   printf("%u, %u, %u\n", arr, &arr[0], &arr);

   return 0;

A. 1200, 1202, 1204

B. 1200, 1200, 1200

C. 1200, 1204, 1208

D. 1200, 1202, 1200

  ANS:B

21.What will be the output of the program ?

#include<stdio.h>

int main()

{
   int arr[1]={10};

   printf("%d\n", 0[arr]);

   return 0;

A. 1

B. 10

C. 0

D. 6

  ANS:B

22.What will be the output of the program if the array begins at address 65486?

#include<stdio.h>

int main()

   int arr[] = {12, 14, 15, 23, 45};

   printf("%u, %u\n", arr, &arr);

   return 0;

A. 65486, 65488

B. 65486, 65486

C. 65486, 65490

D. 65486, 65487

   ANS:B

23.What will be the output of the program ?

#include<stdio.h>
int main()

   float arr[] = {12.4, 2.3, 4.5, 6.7};

   printf("%d\n", sizeof(arr)/sizeof(arr[0]));

   return 0;

A. 5

B. 4

C. 6

D. 7

  ANS:B

  

24.Which of the following statements mentioning the name of the array begins DOES NOT yield the
base address?

1: When array name is used with the sizeof operator.

2: When array name is operand of the & operator.

3: When array name is passed to scanf() function.

4: When array name is passed to printf() function.

A. A

B. A, B

C. B

D. B, D

  ANS:B

  

25.Which of the following statements are correct about an array?

1: The array int num[26]; can store 26 elements.

2: The expression num[1] designates the very first element in the array.
3: It is necessary to initialize the array at the time of declaration.

4: The declaration num[SIZE] is allowed if SIZE is a macro.

A. 1

B. 1,4

C. 2,3

D. 2,4

  ANS:B

1.What will be the output of the program ?

#include<stdio.h>

int main()

   static char *s[] = {"black", "white", "pink", "violet"};

   char **ptr[] = {s+3, s+2, s+1, s}, ***p;

   p = ptr;

   ++p;

   printf("%s", **p+1);

   return 0;

A. ink

B. ack

C. ite

D. let

2.What will be the output of the program ?

#include<stdio.h>

int main()

{
   int i=3, *j, k;

   j = &i;

   printf("%d\n", i**j*i+*j);

   return 0;

A. 30

B. 27

C. 9

D. 3

3.What will be the output of the program ?

#include<stdio.h>

int main()

   int x=30, *y, *z;

   y=&x; /* Assume address of x is 500 and integer is 4 byte size */

   z=y;

   *y++=*z++;

   x++;

   printf("x=%d, y=%d, z=%d\n", x, y, z);

   return 0;

A. x=31, y=502, z=502

B. x=31, y=500, z=500

C. x=31, y=498, z=498

D. x=31, y=504, z=504

4.What will be the output of the program ?

#include<stdio.h>
int main()

   char str[20] = "Hello";

   char *const p=str;

   *p='M';

   printf("%s\n", str);

   return 0;

A. Mello

B. Hello

C. HMello

D. MHello

5.What will be the output of the program If the integer is 4bytes long?

#include<stdio.h>

int main()

   int ***r, **q, *p, i=8;

   p = &i;

   q = &p;

   r = &q;

   printf("%d, %d, %d\n", *p, **q, ***r);

   return 0;

A. 8, 8, 8

B. 4000, 4002, 4004

C. 4000, 4004, 4008

D. 4000, 4008, 4016

 
6.Point out the compile time error in the program given below.

#include<stdio.h>

int main()

   int *x;

   *x=100;

   return 0;

A. Error: invalid assignment for x

B. Error: suspicious pointer conversion

C. No error

D. None of above

7.Point out the error in the program

#include<stdio.h>

int main()

   int a[] = {10, 20, 30, 40, 50};

   int j;

   for(j=0; j<5; j++)

   {

       printf("%d\n", a);

       a++;

   }

   return 0;
}

A. Error: Declaration syntax

B. Error: Expression syntax

C. Error: LValue required

D. Error: Rvalue required

8.What is (void*)0?

A. Representation of NULL pointer

B. Representation of void pointer

C. Error

D. None of above

9.Can you combine the following two statements into one?

char *p;

p = (char*) malloc(100);

A. char p = *malloc(100);

B. char *p = (char) malloc(100);

C. char *p = (char*)malloc(100);

D. char *p = (char *)(malloc*)(100);

10.If a variable is a pointer to a structure, then which of the following operator is used to access data
members of the structure through the pointer variable?

A. .

B. &

C. *

D. ->

11.A pointer is

A. A keyword used to create variables


B. A variable that stores address of an instruction

C. A variable that stores address of other variable

D. All of the above

12.The operator used to get value at address stored in a pointer variable is

A. *

B. &

C. &&

D. ||

13.What will happen if in a C program you assign a value to an array element whose subscript exceeds
the size of array?

A. The element will be set to 0.

B. The compiler would report an error.

C. The program may crash if some important data gets overwritten.

D. The array size would appropriately grow.

14.What does the following declaration mean?

int (*ptr)[10];

A. ptr is array of pointers to 10 integers

B. ptr is a pointer to an array of 10 integers

C. ptr is an array of 10 integers

D. ptr is an pointer to array

15.In C, if you pass an array as an argument to a function, what actually gets passed?

A. Value of elements in array

B. First element of the array

C. Base address of the array

D. Address of the last element of array


16.What will be the output of the program ?

#include<stdio.h>

int main()

   int a[5] = {5, 1, 15, 20, 25};

   int i, j, m;

   i = ++a[1];

   j = a[1]++;

   m = a[i++];

   printf("%d, %d, %d", i, j, m);

   return 0;

A. 2, 1, 15

B. 1, 2, 5

C. 3, 2, 15

D. 2, 3, 20

17.What will be the output of the program if the array begins at 65472 and each integer occupies 2
bytes?

#include<stdio.h>

int main()

   int a[3][4] = {1, 2, 3, 4, 4, 3, 2, 1, 7, 8, 9, 0};

   printf("%u, %u\n", a+1, &a+1);

   return 0;

A. 65474, 65476

B. 65480, 65496
C. 65480, 65488

D. 65474, 65488

18.What will be the output of the program ?

#include<stdio.h>

int main()

   int arr[1]={10};

   printf("%d\n", 0[arr]);

   return 0;

A. 1

B. 10

C. 0

D. 6

19.Which of the following statements mentioning the name of the array begins DOES NOT yield the
base address?

1: When array name is used with the sizeof operator.

2: When array name is operand of the & operator.

3: When array name is passed to scanf() function.

4: When array name is passed to printf() function.

A. A

B. A, B

C. B

D. B, D

20.Which of the following statements are correct about 6 used in the program?

int num[6];
num[6]=21;

A. In the first statement 6 specifies a particular element, whereas in the second statement it specifies
a type.

B. In the first statement 6 specifies a array size, whereas in the second statement it specifies a
particular element of array.

C. In the first statement 6 specifies a particular element, whereas in the second statement it specifies
a array size.

D. In both the statement 6 specifies array size.

21.Which of the following statements are correct about an array?

1: The array int num[26]; can store 26 elements.

2: The expression num[1] designates the very first element in the array.

3: It is necessary to initialize the array at the time of declaration.

4: The declaration num[SIZE] is allowed if SIZE is a macro.

A. 1

B. 1,4

C. 2,3

D. 2,4

22.Which one of the following statements is correct?

A. Array elements can be of integer type only.

B. The rank of an Array is the total number of elements it can contain.

C. The length of an Array is the number of dimensions in the Array.

D. The default value of numeric array elements is zero.

E. The Array elements are guaranteed to be sorted.

23.If a is an array of 5 integers then which of the following is the correct way to increase its size to 10
elements?

A. int[] a = new int[5];

  int[] a = new int[10];


B. int[] a = int[5];

  int[] a = int[10];

C. int[] a = new int[5];

  a.Length = 10 ;

D. int[] a = new int[5];

  a = new int[10];

E. int[] a = new int[5];

  a.GetUpperBound(10);

  

24.Which of the following are the correct ways to define an array of 2 rows and 3 columns?

   int[ , ] a;

   a = new int[2, 3]{{7, 1, 3},{2, 9, 6}};

   int[ , ] a;

   a = new int[2, 3]{};

   int[ , ] a = {{7, 1, 3}, {2, 9,6 }};

   int[ , ] a;

   a = new int[1, 2];

   int[ , ] a;

   a = new int[1, 2]{{7, 1, 3}, {2, 9, 6}};

A. 1, 2 , 3
B. 1, 3

C. 2, 3

D. 2, 4, 5

E. 4, 5

25.Which of the following is the correct way to obtain the number of elements present in the array
given below?

   int[] intMyArr = {25, 30, 45, 15, 60};

   intMyArr.GetMax;

   intMyArr.Highest(0);

   intMyArr.GetUpperBound(0);

   intMyArr.Length;

   intMyArr.GetMaxElements(0);

A. 1, 2

B. 3, 4

C. 3, 5

D. 1, 5

E. 4, 5

1. What will be the output of the following C code?

   #include <stdio.h>

   void foo(int*);

   int main()

   {

       int i = 10;
foo((&i)++);

   void foo(int *p)

   {

       printf("%d\n", *p);

   }

a)10
b) Some garbage value
c) Compile time error
d) Segmentation fault/code crash

2. What will be the output of the following C code?

   #include <stdio.h>

   void foo(int*);

   int main()

   {

       int i = 10, *p = &i;

       foo(p++);

   void foo(int *p)

   {

       printf("%d\n", *p);
   }

a) 10
b) Some garbage value
c) Compile time error
d) Segmentation fault

3. What will be the output of the following C code?

   #include <stdio.h>

   void foo(float *);

   int main()

   {

       int i = 10, *p = &i;

       foo(&i);

   }
   void foo(float *p)

   {

       printf("%f\n", *p);

   }

a) 10.000000
b) 0.000000
c) Compile time error
d) Undefined behaviour

4. What will be the output of the following C code?

   #include <stdio.h>

   int main()

   {

       int i = 97, *p = &i;

       foo(&i);
       printf("%d ", *p);

   }

   void foo(int *p)

   {

       int j = 2;

       p = &j;

       printf("%d ", *p);

   }

a) 2 97
b) 2 2
c) Compile time error
d) Segmentation fault/code crash

 
5. What will be the output of the following C code?

   #include <stdio.h>

   int main()

   {

       int i = 97, *p = &i;

       foo(&p);

       printf("%d ", *p);

       return 0;

   }

   void foo(int **p)


   {

       int j = 2;

       *p = &j;

       printf("%d ", **p);

   }

a) 2 2
b) 2 97
c) Undefined behaviour
d) Segmentation fault/code crash

6. What will be the output of the following C code?

   #include <stdio.h>

   int main()

   {

       int i = 11;
       int *p = &i;

       foo(&p);

       printf("%d ", *p);

   }

   void foo(int *const *p)

   {

       int j = 10;

       *p = &j;

       printf("%d ", **p);


   }

a) Compile time error


b) 10 10
c) Undefined behaviour
d) 10 11

7. What will be the output of the following C code?

   #include <stdio.h>

   int main()

   {

       int i = 10;

       int *p = &i;

       foo(&p);

       printf("%d ", *p);

       printf("%d ", *p);


   }

   void foo(int **const p)

   {

       int j = 11;

       *p = &j;

       printf("%d ", **p);

   }

a) 11 11 11
b) 11 11 Undefined-value
c) Compile time error
d) Segmentation fault/code-crash

1. Write a program to give the following output for the given input

Eg:Input: a1b10
           Output:abbbbbbbbbb

     Input:a3b1c5

          Output:aaabccccc

2.Write a program to delete all vowels from a sentence.Assume that the sentence is not more than 80 characters long.

3.Find the sum of two linked lists using Stack?

4.Print all nodes of a given binary tree using inorder traversal without recursion? 

5.Write a C program to generate digital clock.

6.Write a C program to check given number is strong number or not.

7.How do you check if a string contains only digits?

8.How do you check if two rectangles overlap with each other?

9.How all leaves of binary search tree printed?

10.C program to find the largest number using dynamic memory allocation.

11.How to find all permutations in a string?

12.AAAAA

     BBBB

     CCC

     DD

     E

13.1 

     2 3 

     4 5 6 

     7 8 9 10

     11 12 13 14 15

14 . 55555

        45555

        34555

        23455

        12345

15. 1 2 3 4 5 
        6 7 8 9 

        10 11 12

        13 14

         15

16.   1                    1

            2             2

              3        3

                4    4

                   5

                 4    4

               3         3

             2               2

         1                      1

17.Write a C program to print the following pattern:

*********
**** ****
*** ***
** **
* *
** **
*** ***
**** ****
*********

18.Compute determinant of a matrix.

19.Generate randomised sequence of given range of numbers.

20.Check whether a matrix is sparse matrix ?

You might also like