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

Pointers

Uploaded by

Tej Tej
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views

Pointers

Uploaded by

Tej Tej
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 10

Pointers - General Questions

. What is (void*)0?
A
Representation of NULL pointer
.

B
Representation of void pointer
.

C
Error
.

D
None of above
.
Answer: Option A

Can you combine the following two statements into one?


char *p;
p = (char*) malloc(100);
A
char p = *malloc(100);
.

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. A variable that stores address of an instruction

C. A variable that stores address of other variable


D. All of the above
Answer: Option C

The operator used to get value at address stored in a pointer variable is


A. *

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

B. 4000, 4002, 4004

C. 4000, 4004, 4008

D. 4000, 4008, 4016


Answer: Option A

What will be the output of the program ?


#include<stdio.h>

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;
}

A x=31, y=502, z=502


.

B
x=31, y=500, z=500
.

C
x=31, y=498, z=498
.

D
x=31, y=504, z=504
.
Answer: Option D

What will be the output of the program ?


#include<stdio.h>

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

What will be the output of the program ?


#include<stdio.h>

int main()
{
char *str;
str = "%s";
printf(str, "K\n");
return 0;
}

A. Error

B. No output
C. K

D. %s
Answer: Option C

. What will be the output of the program ?


#include<stdio.h>

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

What will be the output of the program ?


#include<stdio.h>

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

What will be the output of the program ?


#include<stdio.h>

int main()
{
char *p;
p="hello";
printf("%s\n", *&*&p);
return 0;
}

A. llo

B. hello

C. ello

D. h
Answer: Option B

What will be the output of the program ?


#include<stdio.h>

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;
}

A. Error: invalid assignment for x

B. Error: suspicious pointer conversion

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;
}

A. Error: Declaration syntax

B. Error: Expression syntax

C. Error: LValue required

D. Error: Rvalue required


Answer: Option C

Which of the statements is correct about the program?


#include<stdio.h>

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

Which of the statements is correct about the program?


#include<stdio.h>

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

D. It will print a garbage value


Answer: Option A

. Are the expression *ptr++ and ++*ptr are same?


A
True
.

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

. Will the program compile?


#include<stdio.h>
int main()
{
char str[5] = "IndiaBIX";
return 0;
}

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

. The following program reports an error on compilation.


#include<stdio.h>
int main()
{
float i=10, *j;
void *k;
k=&i;
j=k;
printf("%f\n", *j);
return 0;
}

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)

The output: 10.000000


View Answer Discuss in Forum Workspace Report
. Are the three declarations char **apple, char *apple[], and char apple[][] same?
A
True
.

B
False
.
Answer: Option B

Is there any difference between the following two statements?


char *p=0;
char *t=NULL;
A. Yes

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

. Is this a correct way for NULL pointer assignment?


int i=0;
char *q=(char*)i;
A
Yes
.

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

Is the NULL pointer same as an uninitialised pointer?


A
Yes
.

B
No
.
Answer: Option B

. Will the program compile in Turbo C?


#include<stdio.h>
int main()
{
int a=10, *j;
void *k;
j=k=&a;
j++;
k++;
printf("%u %u\n", j, k);
return 0;
}

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

You might also like