0% found this document useful (0 votes)
25 views

C Pointers

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views

C Pointers

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

1) What will be the output of following program ?

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

1. Error
2. IncludeHelp
3. I
4. *I

Answer

2) What will be the output of following program ?

1 #include <stdio.h>
2 int main()
3 {
4 int iVal;
5 char cVal;
6 void *ptr; // void pointer
7 iVal=50; cVal=65;
8
9 ptr=&iVal;
10 printf("value =%d,size= %d\n",*(int*)ptr,sizeof(ptr));
11
12 ptr=&cVal;
13 printf("value =%d,size= %d\n",*(char*)ptr,sizeof(ptr));
14 return 0;
15 }

1. Error
2. value =50,size= 4
value =65,size= 4
3. value =50,size= 4
value =65,size= 1
4. Garbage Values

Answer

3) What will be the output of following program ?

1 #include <stdio.h>
2 int main() /
3 {
4 char *str []={"AAAAA","BBBBB","CCCCC","DDDDD"};
5 char **sptr []={str+3,str+2,str+1,str};
6 char ***pp;
7
8 pp=sptr;
9 ++pp;
10 printf("%s",**++pp+2);
11 return 0;
12 }

1. BBBBB
2. CCCCC
3. BBB
4. Error

Answer

4) What will be the output of following program ?

1 #include <stdio.h>
2 char* strFun(void)
3 {
4 char *str="IncludeHelp";
5 return str;
6 }
7 int main()
8 {
9 char *x;
10 x=strFun();
11 printf("str value = %s",x);
12 return 0;
13 }

1. str value = Garbage value


2. str value = IncludeHelp
3. Error
4. No output

Answer

5) If the address of pointer ptr is 2000, then what will the output of following
program ?
[On 32 bit compiler.]

1 #include <stdio.h>
2 int main()
3 {
4 void *ptr; /
5 ++ptr;
6 printf("%u",ptr);
7 return 0;
8 }

1. 2004
2. 2001
3. 2000
4. ERROR

Answer

6) What will be the output of following program ?

1 #include <stdio.h>
2 int main()
3 {
4 char ch=10;
5 void *ptr=&ch;
6 printf("%d,%d",*(char*)ptr,++(*(char*)ptr));
7 return 0;
8 }

1. 11,11
2. 10,11
3. ERROR
4. 10,10

Answer

7) What will be the output of following program ?

1 #include <stdio.h>
2 int main()
3 {
4 int a=10,b=2;
5 int *pa=&a,*pb=&b;
6 printf("value = %d", *pa/*pb);
7 return 0;
8 }

1. 5
2. 5.0
3. ERROR
4. None of these

Answer
/
8) What will be the output of following program ?

1 #include <stdio.h>
2 void fun(int *ptr)
3 {
4 *ptr=100;
5 }
6 int main()
7 {
8 int num=50;
9 int *pp=#
10 fun(& *pp);
11 printf("%d,%d",num,*pp);
12 return 0;
13 }

1. 100,100
2. 50,50
3. 50,100
4. ERROR in function calling

Answer

You might also like