Welcome Guest | Sign in | Register

Home > C Programming > Pointers > Questions and Answers

01. What will be output of following program?

#include
int main()
{
int a = 320;
char *ptr;
ptr = (char *)&a;
printf("%d",*ptr);
return 0;
}
A. 2 B. 320
C. 64 D. Compilation Error

Answer and Explanation

Answer: 64

Explanation:
As we know int is two byte data byte while char is one byte data byte. Character pointer can keep the address one byte at time.

Binary value of 320 is 00000001 01000000 (In 16 bit) Memory representation of int a = 320 is:

So ptr is pointing only first 8 bit which color is green and Decimal value is 64. 

Report Errors

Name:

Loading...

VView Answer | RReport | DDiscuss in Forum
02. What will be the output

main()
{
char *ptr = "Pskills.org";
char a =
printf("%c", ++*ptr++);
}
A. Compilation Error B. Q
C. P D. a

Answer and Explanation

Answer: Q

Explanation:
++*ptr++ will retrieve the value currently pointed by ptr i.e P and then increment the value and will print Q.

Report Errors

Name:

Loading...

VView Answer | RReport | DDiscuss in Forum
03. What is the output of the following program?

void main(){
int a;
a=3+5*5+3;
printf("%d",a);
}
A. 43 B. 64
C. 31 D. none of these

Answer and Explanation

Answer: 31

Explanation:
There is no explanation...

Report Errors

Name:

Loading...

VView Answer | RReport | DDiscuss in Forum
04. What is the output of following program?

void main(){
printf("%d%d",47%5,47%-5);
printf("%d%d%d",-47%5,-47%-5,5%7);
}
A. 2,-2,-2,-2,5 B. 2,2,-2,-2,5
C. 2,-2,2,-2,5 D. 2,2,-2,-2,0

Answer and Explanation

Answer: 2,2,-2,-2,5

Explanation:
There is no explanation...

Report Errors

Name:

Loading...

VView Answer | RReport | DDiscuss in Forum
05. 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 and Explanation

Answer: 12 13 15 16 16

Explanation:
There is no explanation...

Report Errors

Name:

Loading...

VView Answer | RReport | DDiscuss in Forum
06. What is the output of following program?

void main(){
int a=89;
int p;
p=&a;
*(int*)p=8;
printf("%d",a);
return 0;
}
A. 7 B. 8
C. 89 D. error

Answer and Explanation

Answer: error

Explanation:
error L value required  

Report Errors

Name:

Loading...

VView Answer | RReport | DDiscuss in Forum
07. What will be the output?

main()
{
int i, j, *ptr, *ptr1;
i = 10;
j = 10;
ptr = &i;
ptr1 = &j;
if(ptr == ptr1)
{
printf("True");
}
else
{
printf("False");
}
}  
A. True B. False
C. Syntax Error D. Run time Error

Answer and Explanation

Answer: False

Explanation:
In this program we are comparing the addresses contained by ptr & ptr1 not the value at those addresses and pointers ptr and ptr1 have the addresses of different variables so above condition is false

Report Errors

Name:

Loading...

VView Answer | RReport | DDiscuss in Forum
08. What will be output if you will compile and execute the following c code? 
 
#include
int main(){
char huge *p=(char *)0XC0563331;
char huge *q=(char *)0XC2551341;
if(p==q)
printf("Equal");
else if(p>q)
printf("Greater than");
else printf("Less than");
return 0;
}  
A. Equal B. Greater than
C. Less than D. Compiler error
E. None of above

Answer and Explanation

Answer: Equal

Explanation:
As we know huge pointers compare its physical address. Physical address of huge pointer p Huge address: 0XC0563331 Offset address: 0x3331 Segment address: 0XC056 Physical address= Segment address * 0X10 + Offset address =0XC056 * 0X10 +0X3331 =0XC0560 + 0X3331 =0XC3891 Physical address of huge pointer q Huge address: 0XC2551341 Offset address: 0x1341 Segment address: 0XC255 Physical address= Segment address * 0X10 + Offset address =0XC255 * 0X10 +0X1341 =0XC2550 + 0X1341 =0XC3891 Since both huge pointers p and q are pointing same physical address so if condition will true.

Report Errors

Name:

Loading...

VView Answer | RReport | DDiscuss in Forum



Partner Sites
LucentBlackBoard.com                  SoftLucent.com                  LucentJobs.com
All rights reserved © 2012-2015 SoftLucent.