C Pointers - Placement questions and answers

C Pointers - Placement questions and answers


1. How can you write a[i][j][k][l] in equivalent pointer expression?

a) (((***(a+i)+j)+k)+l)
b) ((**(*(a+i)+j)+k)+l)
c) (*(*(*(a+i)+j)+k)+l)
d) *(*(*(*(a+i)+j)+k)+l)

View Answer / Hide Answer

ANSWER: D




2. Can this be written in any other way?

char far *src = (char far*)0xB800000L

a) char far *src ; src = (char far*)0xB800000L .
b) char far src ; src* = (char far*)0xB800000L.
c) (char *)far src ; src = (char far*)0xB800000L .
d) None.

View Answer / Hide Answer

ANSWER: A




3. Would the following program give any warning on compilation?

#include ”stdio.h”
main()
{
int *p1, i=25;
void *p2;
p1 =&i;
p2=&i;
p1=p2;
p2=p1;
}

a) Yes.
b) No.

View Answer / Hide Answer

ANSWER: B




4. What would be the output of the following program?

main()
{
char far *a=0x00000120;
char far *b=0x00100020;
char far *c=0x00120000;


if(a==b)
printf(“\nHello”);

if(a==c)
printf(“\nHi”);
if(b==c)
printf(“\nHello Hi”);
if(a>b && a>c&& b>c)
printf(“\nBye”);

}

a) Hello
b) Hi
c) Hello Hi
d) Bye

View Answer / Hide Answer

ANSWER: D




5. What would be the output of the following program?

#include”stdio.h”
main()
{
int a, b=5;
a=b+NULL;
printf(“%d”, a);
}

a) 6
b) 5
c) 5 5
d) None

View Answer / Hide Answer

ANSWER: B




6. How would you eliminate the warning generated on compiling the following program?

main()
{
char far *src;
src=0xB8000000;
*src=’A’;
}

a) Use other address
b) Use typecast (char far*) 0xB8000000.
c) Use typecast (char * far ) 0xB8000000.
d) None

View Answer / Hide Answer

ANSWER: B




7. Would the following code compile successfully?

main()
{

Printf(“%c”,7[‘Sundaram’]);

}

a) Yes it will print sundara.
b) No it will show compilation error.
c) Yes print m of sundaram.
d) None

View Answer / Hide Answer

ANSWER: C




8. In which header file is the NULL macro defined?

a) In stdio.h
b) In stdio.h & math.h
c) In stdio.h & stddef.h
d) None

View Answer / Hide Answer

ANSWER: C




9. In the following program how would you print 50 using p?

main()
{
Int a[]={10,20,30,40,50};
char *p;
p = (char *)a
}

a) printf(“\n%c”, ((int *)p+4));
b) printf(“\n%d”,(*(int *)p+4));
c) printf(“\n%d”,*((int *)p+4));
d) None.

View Answer / Hide Answer

ANSWER: C




10. What would be the output of the following program?

main()
{
Int arr[]={12, 13, 14, 15, 16};
Printf(“\n%d %d %d”, sizeof(arr), sizeof(*arr), sizeof(arr[0]));
}

a) 12 13 14 16
b) 10 12 15 16
c) 10 2 2
d) None

View Answer / Hide Answer

ANSWER: C




11. What would be the output of the following program assuming that the array begins at location 1002?

main()
{
Int a[2][3][4] =
{

{1, 2, 3, 4,
5, 6, 7, 8,
9, 1, 1, 2
},

{2, 1, 4, 7,
6, 7, 8, 9,
0, 0, 0, 0
}

};

Printf(“\n%u %u %u %d”, a, *a, **a, ***a);

}

a) 1002 1002 1002 1
b) 1002 1002 1002 2
c) 1002 1002 1003 3
d) 1002 1002 1004 4

View Answer / Hide Answer

ANSWER: A




12. What would be the output of the following program.

#include<stdio.h>

main()
{
printf(“%d %d”, sizeof(NULL), sizeof(‘’));
}

a) 2 2
b) 2 1
c) 2 3
d) 2 4

View Answer / Hide Answer

ANSWER: B




13. Would the following program compile?

main()
{
int a=10, *j;
void *k;
J = k = &a;
J++;
K++;
printf(“\n%u %u”, j, k);
}

a) Yes, there is no problem in the code.
b) Yes, but void *k is not correct.
c) No, an error on the K++ statement
d) No

View Answer / Hide Answer

ANSWER: C




14. Are three declaration char **apple, char *orange [] and char cherry [][] same?

a) No
b) Yes

View Answer / Hide Answer

ANSWER: A




15. What is NULL pointer

a) Denote pointer to 0
b) Denote integer pointer to 0
c) Denote NULL pointer is the integer 0
d) None

View Answer / Hide Answer

ANSWER: C




16. Can you combine two statements in to one?

Char *p;
p = malloc (100);

a) Char *p = malloc(100);
b) Char p = malloc(100);
c) Char *p[] = malloc (sizeof(100));
d) None

View Answer / Hide Answer

ANSWER: A




17. What is wild pointer?

a) Pointer which is wild in nature
b) Pointer which has no value.
c) Pointer which is not initialized
d) None

View Answer / Hide Answer

ANSWER: C




18. Why can’t I perform arithmetic on void * pointer?

a) Compiler does not know the size of object
b) Compiler does not allow Void *
c) Compiler don’t have value to initialized
d) None

View Answer / Hide Answer

ANSWER: A




19. Suppose I want to write a function that takes a generic pointer as an argument and I want to simulate passing it by reference. Can I give the formal parameter type void **, and do

something like this?

void f(void **);
double *dp;
f((void **)&dp);

a) Not portably
b) The good way to write
c) Problem with f((void **)&dp);
d) None

View Answer / Hide Answer

ANSWER: A




20. Does *p++ increment p, or what it points to?

a) Increment the value which is pointed by p
b) Increment the value of p not the value pointed
c) Only increment *p value
d) None

View Answer / Hide Answer

ANSWER: C



Post your comment

    Discussion

  • RE: C Pointers - Placement questions and answers -Nikum (10/05/14)
  • All questions are v.gud..