You are on page 1of 52

Pointers

and
Functions
14-7-2014
Pointers
1. What is the output of the following
program?
main()
{
int a=10;
int *b;
b=&a;
a=20;
Printf(%d,*b);
}
a)10
b)20
c)Garbage value
d)error
2.What is the output of the following
program?
main()
{
int a=A;
char *c;
c=(char * )&a;
printf(%c,*c);
}
a)NULL
b)0
c)A
d)garbage value
3. what will be the output of the
following program?
int main()
{
int i=3, *j, k;
j = &i;
printf("%d\n", i**j*i+*j);
return 0;
}
a)30
b)20
c)300
d)garbage value




4. If the starting address of the array
a[] is 1000 and integer size is 2
Bytes.then what is the output of
the following program?

main()
{
int a[]={1,2,3,4,5};
printf(%u,a+2);
}
a)1004
b)1002
c)1000
d)1006


5. If the starting address of the array
a[] is 1000 then what is the output of
the following program?

main()
{
int a[]={1,2,3,4,5};
printf(%u,*(a+2));
}
a) 4
b) 2
c) 1
d) 3
6.what is the output of the following
program?
main()
{
char a*+=hello how r u;
int i;
for(i=0;i<=4;i++)
{
printf(%c,*(a+i));
}
}
a)hello
b)ello
c)hello how r u
d)error
7.what is the output of the following
program?
main()
{
int a,*b,**c;
a=120;
b=&a;
c=&b;
printf(%d,**c);
}
a)120
b)garbage value
c)20
d)error
8.what is the output of the following
program?
main()
{
int a,*b,**c;
a=12;
b=&a;
*b=10;
c=&b;
**c=20;
printf(%d,a);
}
a)10
b)20
c)12
d)22
9.what will be the output of the
following program?
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;
}
10.what is the output of the following
program?
main()
{
int a=12,*b;
void *c;
c=&a;
b=&a;
*b=9;
printf(%d,*(int *)c);
}

a)9
b)12
c)21
d)garbage value

11. what will be the output of the
following program?
main()
{
int a=10,b=20;
int *const p=&a;
p=&b;
printf("%d",*p);
}
a) 20
b) 10
c) compiler error
d) garbage value
12.what will be the output of the
following program?
main()
{
int a=10,b=20;
int *const p=&a;
a=b;
printf(%d,*p);
}
a)10
b)20
c)compiler error
d)garbage value
13.what will be the output of the
following program?
main()
{
int a=10,b=20;
const int *p=&a;
p=&b;
printf(%d,*p);
}
a)10
b)20
c)error
d)garbage value
14.what will be the output of the
following program?
main()
{
int a=10,b=20;
const int *p=&a;
*p=b;
printf(%d,*p);
}

a) 20
b) 10
c) compile time error
d) garbage value

15.what will be the output of the
following program on a 16 bit
platform?
#include<stdio.h>
main()
{
printf(%d %d, sizeof(NULL), sizeof();
}

a) 1 1 b)2 1 c)2 2 d)4 2

FUNCTIONS
1.what is the output of the following
program?

main()
{
printf(hello);
main();
}
a) Prints hello until stack
overflows
b) Prints hello infinitely
c) main should not be
called in main()
d) No output
2.what is the output of the following
program?
main()
{
float b;
b=sum(10.1,20.2);
printf(%f, b);
}
float sum(float a, float b)
{
float c;
c=a+b;
return c;
}
a) Declaration syntax error b)30.300000 c)30 d)30.3
3.what is the output of the following
program?
main()
{
int a=10,b=20;
swap(a,b);
printf(%d%d, a, b);
}


swap(int a,int b)
{
int t;
t=a;
a=b;
b=t;
}
a) 10 20 b)20 10 c)20 30 d)30 10
4. what will be the output of the following program?
#include<stdio.h>
void fun(int, int);
int main()
{
int i=5, j=2;
fun(i, j);
printf("%d, %d", i, j);
return 0;
}
void fun(int i, int j)
{
i = i*i;
j = j*j;
}



a)25 4
b)5 2
c)compiler error
d)garbage values

5.what will be the output of the following program?
#include<stdio.h>
int i;
int fun();
int main()
{
while(i)
{
fun();
main();
}
printf("Hello\n");
return 0;
}
int fun()
{
printf("Hi");
}

a) Hello b)Hi Hello

c)displays Hi, Hello infinitely

d)no output
6. #include<stdio.h>
int fun(int);
int main()
{
int no=5;
fun(no);
return 0;
}
int fun(int no)
{
if(no == 0) return 0;
else printf("%d,", no);
fun(no--);
}

a)5 4 3 2 1
b)5 4 3 2 1 0
c)1 2 3 4 5
d)displays 5 until stack
overflows.

7. #include<stdio.h>
void fun(int);
int main()
{
int a=3;
fun(a);
return 0;
}
void fun(int n)
{
if(n > 0)
{
fun(--n);
printf("%d,", n);
fun(--n);
}
}

A) 0, 2, 1, 0, B) 1, 1, 2, 0,

C) 0, 1, 0, 2, D) 0, 1, 2, 0,

8. #include<stdio.h>
int main()
{
void fun(char*);
char a[100];
a[0] = 'A'; a[1] = 'B'; a[2] = 'C'; a[3] = 'D';
fun(&a[0]);
return 0;
}
void fun(char *a)
{
a++;
printf("%c", *a);
a++;
printf("%c", *a);
}
a.)AB b.)BC

c.)CD d.)No output
9.what will be the output of the following?
#include<stdio.h>
int main()
{
int fun(int);
int i = fun(10);
printf("%d\n", --i);
return 0;
}

int fun(int i)
{
return (i++);
}
A.)9 B.)10 C.)11 D.)8
11.what is the output of the following
program?
main()
{
printf(%d,add(5,6));
}

add(char a,char b)
{
char c;
c=a+b;
return c;
}
a) 11
b) 56
c) 59
d) 60

12.what is the output of the following
program?
main()
{
void swap(int *,int *)
int a=20, b=30;
swap(&a,&b);
printf(%d %d,a,b);
}
void swap(int *x, int *y)
{
int t;
t=*x;
*x=*y;
*y=t;
}
a) 20 30 b)30 20 c)30 30 d)20 20
13.what is the output of the following
program?
main()
{
int a=5,b=4;
int c;
c=fun(a,b);
printf(%d,c);
}

int fun(int a,int b)
{
if(b==0)
return 0;
else if(a==0)
return 0;
else
return a+fun(a,--b);
}
a)9 b)20 c)54 d)garbage value
14.what is the output of the following
program?
main()
{
int a;
int c;
scanf(%d,&a);
c=fun(a)
printf(%d,c);
}


int fun(int a)
{
if(a==0 ||a==1)
return 1;
else
return a*fun(a-1);
}
15.what is the output of the following
program?
main()
{
int i;
int a=10;
for(i=1;i<=3;i++)
{
fun(a);
}
printf(%d,a);
}
fun(int a)
{
a++;
}
a) 11 b)13 c)14 d)10
16.what is the output of the following
program?
main()
{
static int i;
int j;
for(i=1;i<=5;i++)
j=fun();
printf(%d, j);
}


fun()
{
static int a;
a++;
return a;
}
a)5 b)4 c)6 d)error
17. what is the output of the following
program?
fun(char *a)
{
a++;
}
main()
{
char *s=welcome;
fun(s);
printf(%s,s);

}
a)welcome
b)elcome
c)lcome
d)error
18. what is the output of the following
program?
int i=10;
main()
{
int i;
printf(%d,i++);
}
19. what is the output of the following
program?
main()
{
int (*p)(int,int);
int add(int,int);
p=add;
printf(%d,p(13,43));
}

int add(int a,int b)
{
return (a+b);
}
a)34 b)56 c)45 d)Error

STRUCTURES & UNIONS


1.Which of the following are
themselves a collection of different
data types?

a)String
b)Int
c)Structure
d)array
2.) How will you free the allocated memory ?

a)remove(var-name);
b) free(var-name);
c) delete(var-name);
d) dalloc(var-name);
3.What will be output of the following
program?
struct student
{
int rollno=1;
char *name=xyz;
};
main()
{
struct student s;
printf(%d,s.rollno);
}
a)1
b)xyz
c)1 xyz
d)error

4.what will be the output of the
following program?
struct student
{
int rollno;
char *name;
};
main()
{
struct student s=,12,xyz-;
printf(%d \t %s,s.rollno,s.name);
}

a)12 xyz
b)12
c)error
d)xyz

5.What will be the output of the
program ?

#include<stdio.h>
main()
{
union a
{
int i;
char ch[2];
};
union a u;
u.ch[0]=3;
u.ch[1]=2;
printf("%d, %d, %d\n", u.ch[0], u.ch[1], u.i);
}
A. 3, 2, 515
B. 515, 2, 3
C. 3, 2, 5
D. 3, 2 , 32
6.which of the following operator
connects the structure name to its
member?
a) >
b) <
c) .
d) <-
7. What will be the output of the
program ?
#include<stdio.h>
int main()
{
union var
{
int a, b;
};
union var v;
v.a=10;
v.b=20;
printf("%d\n", v.a);
}
A. 10
B. 20
C. 30
D. 0

8. What will be the output of the
program ?

int main()
{
struct value
{
int b1:1;
int b3:4;
int b4:4;
}b={1, 2, 13};
printf("%d, %d, %d\n", b.b1, b.b3, b.b4);
}
a)1 4 4
b)1 2 3
c)-1 2 -3
d)1 2 13
9. What will be the output of the
program in 16 bit platform?
main()
{
struct value
{
int bit1:1;
int bit3:4;
int bit4:3;
}bit;
printf("%d\n", sizeof(bit));
}
A.1
B.2
C.4
D. 9
10.What will be the output of the
program ?
main()
{
enum days {MON=-1, TUE, WED=6, THU, FRI, SAT};
printf("%d, %d, %d, %d, %d, %d\n", MON, TUE, WED, THU, FRI, SAT);
}
A. -1, 0, 1, 2, 3, 4
B. -1, 2, 6, 3, 4, 5
C. -1, 0, 6, 2, 3, 4
D. -1, 0, 6, 7, 8, 9
11.What will be the output of the
program ?
main()
{
enum status {pass, fail, absent};
enum status stud1, stud2, stud3;
stud1 = pass;
stud2 = absent;
stud3 = fail;
printf("%d %d %d\n", stud1, stud2, stud3);
}
a)1 2 3
b)0 1 2
c)0 2 1
d)1 1 1
12.What will be the output of the
program ?
main()
{
struct node
{ int data;
struct node *link;
};
struct node *p, *q;
p = (struct node *) malloc(sizeof(struct node));
q = (struct node *) malloc(sizeof(struct node));
printf("%d, %d\n", sizeof(p), sizeof(q));
}
a)4 4
b)2 2
c)8 8
d)4 8
13.what will be output of the following
program?
typedef char* string;
main()
{
string p=hello;
printf(%s,p);
}
14.What will be the output of the
program ?
typedef char* string;
main()
{
typedef string ss;
ss p=hello;
printf(%s,p);
}

15.what will be the output of the
program ?
main()
{
enum days {MON=-1, TUE, WED=6, THU, FRI, SAT};
printf("%d, %d, %d, %d, %d, %d\n", ++MON, TUE,
WED, THU, FRI, SAT);
}

You might also like