Welcome Guest | Sign in | Register

Home > C Programming > Pointers > Questions and Answers

01. Predict the output or error(s) for the following?

void main()
{
int const * p=5;
printf("%d",++(*p));
}
A. Compiler error B. 5
C. 6 D. 7

Answer and Explanation

Answer: Compiler error

Explanation:
Compiler error: Cannot modify a constant value.

p is a pointer to a "constant integer".

Report Errors

Name:

Loading...

VView Answer | RReport | DDiscuss in Forum
02. Predict the output or error(s) for the following?

main()
{
int a[2][2][2] = { {10,2,3,4}, {5,6,7,8} };
int *p,*q;
p=&a[2][2][2];
*q=***a;
printf("%d----%d",*p,*q);
}
A. SomeGarbageValue---1 B. 0
C. Compiler Error D. 2..6

Answer and Explanation

Answer: SomeGarbageValue---1

Explanation:
p=&a[2][2][2] you declare only two 2D arrays, but you are trying to access the third 2D(which you are not declared) it will print garbage values. *q=***a starting address of a is assigned integer pointer. Now q is pointing to starting address of a. If you print *q, it will 

Report Errors

Name:

Loading...

VView Answer | RReport | DDiscuss in Forum
03. Predict the output or error(s) for the following?

main()
{
char *p;
p="Hello";
printf("%c\n",*&*p);
}
A. Garbage Value B. 0
C. Compiler Error D. H

Answer and Explanation

Answer: H

Explanation:
There is no explanation...

Report Errors

Name:

Loading...

VView Answer | RReport | DDiscuss in Forum
04. Predict the output or error(s) for the following?

main()
{
char s[]={'a','b','c','\n','c','\0'};
char *p,*str,*str1;
p=&s[3];
str=p;
str1=s;
printf("%d",++*p + ++*str1-32);
}
A. Garbage Value B. 0
C. M D. None of these

Answer and Explanation

Answer: M

Explanation:
p is pointing to character '\n'.str1 is pointing to character 'a' ++*p meAnswer:"p is pointing to '\n' and that is incremented by one." the ASCII value of '\n' is 10. then it is incremented to 11. the value of ++*p is 11. ++*str1 meAnswer:"str1 is pointing to 'a' that is incremented by 1 and it becomes 'b'. ASCII value of 'b' is 98. both 11 and 98 is added and result is subtracted from 32.
i.e. (11+98-32)=77("M");

Report Errors

Name:

Loading...

VView Answer | RReport | DDiscuss in Forum
05. Predict the output or error(s) for the following?

main()
{
char *cptr,c;
void *vptr,v;
c=10; v=0;
cptr=&c; vptr=&v;
printf("%c%v",c,v);
}
A. No output B. 0
C. Compiler error D. None of these

Answer and Explanation

Answer: Compiler error

Explanation:
Compiler error (at line number 4): size of v is Unknown.

You can create a variable of type void * but not of type void, since void is an empty type. In the second line you are creating variable vptr of type void * and v of type void hence an error.


Report Errors

Name:

Loading...

VView Answer | RReport | DDiscuss in Forum
06. Predict the output or error(s) for the following?

main()
{
char *str1="abcd";
char str2[]="abcd";
printf("%d %d %d",sizeof(str1),sizeof(str2),sizeof("abcd"));
}
A. 2 5 3 B. 0
C. 2 5 5 D. 2 3 4

Answer and Explanation

Answer: 2 5 5

Explanation:
There is no explanation...

Report Errors

Name:

Loading...

VView Answer | RReport | DDiscuss in Forum
07. Predict the output or error(s) for the following?

main()
{
int *j;
{
int i=10;
j=&i;
}
printf("%d",*j);
}
A. 8 B. 0
C. 9 D. 10

Answer and Explanation

Answer: 10

Explanation:
The variable i is a block level variable and the visibility is inside that block only. But the lifetime of i is lifetime of the function so it lives upto the exit of main function. Since the i is still allocated space, *j prints the value stored in i since j points i.

Report Errors

Name:

Loading...

VView Answer | RReport | DDiscuss in Forum
08. Predict the output or error(s) for the following?

main()
{
char *p;
p="%d\n";
p++;
p++;
printf(p-2,300);
}
A. 400 B. 100
C. 200 D. 300

Answer and Explanation

Answer: 300

Explanation:
The pointer points to % since it is incremented twice and again decremented by 2, it points to '%d\n' and 300 is printed.

Report Errors

Name:

Loading...

VView Answer | RReport | DDiscuss in Forum
09. Predict the output or error(s) for the following?

void main()
{
void *v;
int integer=2;
int *i=&integer;
v=i;
printf("%d",(int*)*v);
}
A. No output B. 2
C. Compiler error D. None of these

Answer and Explanation

Answer: Compiler error

Explanation:
We cannot apply indirection on type void*.

Void pointer is a generic pointer type. No pointer arithmetic can be done on it. Void pointers are normally used for,


1. Passing generic pointers to functions and returning such pointers.
2. As a intermediate pointer type.
3. Used when the exact pointer type will be known at a later point of time.

Report Errors

Name:

Loading...

VView Answer | RReport | DDiscuss in Forum
10. Which of the following is the proper declaration of a pointer?
A. int x; B. int &x;
C. ptr x; D. int *x;

Answer and Explanation

Answer: int *x;

Explanation:
There is no explanation...

Report Errors

Name:

Loading...

VView Answer | RReport | DDiscuss in Forum



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