Frequently
asked technical objective types multiple choice pointer questions with
explanation of placement in c programming language
Note: Linux GCC compilers and Visual C++ compiler doesn't support far and huge pointers.
1.
What will be output of following program?
#include<stdio.h>
int main(){
int a = 320;
char *ptr;
ptr =( char *)&a;
printf("%d ",*ptr);
return 0;
}
Explanation:
Turbo C++ 3.0: 64
Turbo C ++4.5: 64
Linux GCC: 64
Visual C++: 64
As we know int is two byte data byte while char is one byte data byte. char 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.
20.
What will be output of following program?
#include<stdio.h>
int main(){
int i = 3;
int *j;
int **k;
j = &i;
k = &j;
printf("%u %u %u",i,j,k);
return 0;
}
Explanation:
Turbo C++ 3.0: 3 Address Address
Turbo C ++4.5: 3 Address Address
Linux GCC: 3 Address Address
Visual C++: 3 Address
Address
Here 6024, 8085, 9091 is any arbitrary address, it may be different.
No comments:
Post a Comment