Pointers
Pointers
. What is (void*)0?
A
Representation of NULL pointer
.
B
Representation of void pointer
.
C
Error
.
D
None of above
.
Answer: Option A
B
char *p = (char) malloc(100);
.
C
char *p = (char*)malloc(100);
.
D
char *p = (char *)(malloc*)(100);
.
Answer: Option C
If a variable is a pointer to a structure, then which of the following operator is used to access data
members of the structure through the pointer variable?
A. .
B. &
C. *
D. ->
Answer: Option D
A pointer is
A. A keyword used to create variables
B. &
C. &&
D. ||
Answer: Option A
What will be the output of the program If the integer is 4bytes long?
#include<stdio.h>
int main()
{
int ***r, **q, *p, i=8;
p = &i;
q = &p;
r = &q;
printf("%d, %d, %d\n", *p, **q, ***r);
return 0;
}
A. 8, 8, 8
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;
}
B
x=31, y=500, z=500
.
C
x=31, y=498, z=498
.
D
x=31, y=504, z=504
.
Answer: Option D
int main()
{
int i=3, *j, k;
j = &i;
printf("%d\n", i**j*i+*j);
return 0;
}
A
30
.
B
27
.
C
9
.
D
3
.
Answer: Option A
int main()
{
char *str;
str = "%s";
printf(str, "K\n");
return 0;
}
A. Error
B. No output
C. K
D. %s
Answer: Option C
int main()
{
void *vp;
char ch=74, *cp="JACK";
int j=65;
vp=&ch;
printf("%c", *(char*)vp);
vp=&j;
printf("%c", *(int*)vp);
vp=cp;
printf("%s", (char*)vp+2);
return 0;
}
A
JCK
.
B
J65K
.
C
JAK
.
D
JACK
.
Answer: Option D
int main()
{
printf("%c\n", 7["IndiaBIX"]);
return 0;
}
A
Error: in printf
.
B
Nothing will print
.
C
print "X" of IndiaBIX
.
D
print "7"
.
Answer: Option C
int main()
{
char *p;
p="hello";
printf("%s\n", *&*&p);
return 0;
}
A. llo
B. hello
C. ello
D. h
Answer: Option B
int main()
{
char str1[] = "India";
char str2[] = "BIX";
char *s1 = str1, *s2=str2;
while(*s1++ = *s2++)
printf("%s", str1);
printf("\n");
return 0;
}
A. IndiaBIX
B. BndiaBIdiaBIXia
C. India
D. (null)
Answer: Option B
Point out the compile time error in the program given below.
#include<stdio.h>
int main()
{
int *x;
*x=100;
return 0;
}
C. No error
D. None of above
Answer: Option C
Explanation:
While reading the code there is no error, but upon running the program having an unitialised variable
can cause the program to crash (Null pointer assignment).
Point out the error in the program
#include<stdio.h>
int main()
{
int a[] = {10, 20, 30, 40, 50};
int j;
for(j=0; j<5; j++)
{
printf("%d\n", a);
a++;
}
return 0;
}
int main()
{
int i=10;
int *j=&i;
return 0;
}
[A]
j and i are pointers to an int
.
[B]
i is a pointer to an int and stores address of j
.
[C]
j is a pointer to an int and stores address of i
.
[D]
j is a pointer to a pointer to an int and stores address of i
.
Answer: Option C
int main()
{
float a=3.14;
char *j;
j = (char*)&a;
printf("%d\n", *j);
return 0;
}
A. It prints ASCII value of the binary number present in the first byte of a float variable a.
B. It prints character equivalent of the binary number present in the first byte of a float variable a.
C. It will print 3
B
False
.
Answer: Option B
Explanation:
*ptr++ increments the pointer and not the value, whereas the ++*ptr increments the value
being pointed by ptr
View Answer Discuss in Forum Workspace Report
A
True
.
B
False
.
Answer: Option A
Explanation:
C doesn't do array bounds checking at compile time, hence this compiles.
But, the modern compilers like Turbo C++ detects this as 'Error: Too many initializers'.
GCC would give you a warning.
View Answer Discuss in Forum Workspace Report
A
True
.
B
False
.
Answer: Option B
Explanation:
This program will NOT report any error. (Tested in Turbo C under DOS and GCC under Linux)
B
False
.
Answer: Option B
B. No
Answer: Option B
Explanation:
NULL is #defined as 0 in the 'stdio.h' file. Thus, both p and t are NULL pointers.
View Answer Discuss in Forum Workspace Report
B
No
.
Answer: Option B
Explanation:
The correct way is char *q=0 (or) char *q=(char*)0
View Answer Discuss in Forum Workspace Report
B
No
.
Answer: Option B
A
Yes
.
B
No
.
Answer: Option B
Explanation:
Error in statement k++. We cannot perform arithmetic on void pointers.
The following error will be displayed while compiling above program in TurboC.
Compiling PROGRAM.C:
Error PROGRAM.C 8: Size of the type is unknown or zero.
View Answer Discuss in Forum Workspace Report
Will the following program give any warning on compilation in TurboC (under DOS)?
#include<stdio.h>
int main()
{
int *p1, i=25;
void *p2;
p1=&i;
p2=&i;
p1=p2;
p2=p1;
return 0;
}
A
Yes
.
B
No
.
Answer: Option B