pointers
DESCRIPTION
technical questions on pointers and functionsTRANSCRIPT
-
5/21/2018 Pointers
1/52
Pointersand
Functions
14-7-2014
-
5/21/2018 Pointers
2/52
Pointers
-
5/21/2018 Pointers
3/52
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 valued)error
-
5/21/2018 Pointers
4/52
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)Ad)garbage value
-
5/21/2018 Pointers
5/52
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
-
5/21/2018 Pointers
6/52
4. If the starting address of the array
a[] is 1000and integer size is 2
Bytes.then what is the output ofthe following program?
main(){
int a[]={1,2,3,4,5};
printf(%u,a2);
}
a)1004
b)1002
c)1000d)1006
-
5/21/2018 Pointers
7/52
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,(a2));
}
a) 4b) 2
c) 1
d) 3
-
5/21/2018 Pointers
8/52
6.what is the output of the following
program?
main()
{
char a*+=hello how r u;
int i;
for(i=0;i
-
5/21/2018 Pointers
9/52
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
-
5/21/2018 Pointers
10/52
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
-
5/21/2018 Pointers
11/52
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;
}
-
5/21/2018 Pointers
12/52
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)12c)21
d)garbage value
-
5/21/2018 Pointers
13/52
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)10c) compiler error
d) garbage value
-
5/21/2018 Pointers
14/52
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 errord)garbage value
-
5/21/2018 Pointers
15/52
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)10b)20
c)error
d)garbage value
-
5/21/2018 Pointers
16/52
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)10c) compile time error
d) garbage value
-
5/21/2018 Pointers
17/52
15.what will be the output of the
following program on a 16 bit
platform?#include
main()
{
printf(%d %d, sizeof(NULL), sizeof();
}
a) 1 1 b)2 1 c)2 2 d)4 2
-
5/21/2018 Pointers
18/52
FUNCTIONS
-
5/21/2018 Pointers
19/52
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
-
5/21/2018 Pointers
20/52
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
-
5/21/2018 Pointers
21/52
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
-
5/21/2018 Pointers
22/52
4. what will be the output of the following program?
#include
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 errord)garbage values
-
5/21/2018 Pointers
23/52
5.what will be the output of the following program?
#include
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
-
5/21/2018 Pointers
24/52
6. #include
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 0c)1 2 3 4 5
d)displays 5 until stack
overflows.
-
5/21/2018 Pointers
25/52
7. #include
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,
-
5/21/2018 Pointers
26/52
8. #include
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
-
5/21/2018 Pointers
27/52
9.what will be the output of the following?
#include
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
-
5/21/2018 Pointers
28/52
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) 59d)60
-
5/21/2018 Pointers
29/52
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
-
5/21/2018 Pointers
30/52
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
-
5/21/2018 Pointers
31/52
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);
}
-
5/21/2018 Pointers
32/52
15.what is the output of the following
program?
main()
{
int i;
int a=10;
for(i=1;i
-
5/21/2018 Pointers
33/52
16.what is the output of the following
program?
main()
{
static int i;
int j;
for(i=1;i
-
5/21/2018 Pointers
34/52
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
-
5/21/2018 Pointers
35/52
18. what is the output of the following
program?
int i=10;
main()
{
int i;
printf(%d,i++);
}
-
5/21/2018 Pointers
36/52
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
-
5/21/2018 Pointers
37/52
STRUCTURES & UNIONS
-
5/21/2018 Pointers
38/52
1.Which of the following are
themselves a collection of differentdata types?
a)String
b)Int
c)Structure
d)array
-
5/21/2018 Pointers
39/52
2.) How will you free the allocated memory ?
a)remove(var-name);
b) free(var-name);
c) delete(var-name);
d) dalloc(var-name);
-
5/21/2018 Pointers
40/52
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
-
5/21/2018 Pointers
41/52
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)12c)error
d)xyz
-
5/21/2018 Pointers
42/52
5.What will be the output of the
program ?
#includemain()
{
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
h h f h f ll
-
5/21/2018 Pointers
43/52
6.which of the following operator
connects the structure name to its
member?a) >
b)