C Advanced Pointer

Last Updated :
Discuss
Comments

Question 1

C
void fun(int *p)  {    int q = 10;    p = &q;  }         int main()  {    int r = 20;    int *p = &r;    fun(p);    printf("%d", *p);    return 0;  } 
  • 10

  • 20

  • Compiler error

  • Runtime Error

Question 2

Assume sizeof an integer and a pointer is 4 byte. Output? C
#include <stdio.h>  #define R 10 #define C 20  int main() {    int (*p)[R][C];    printf("%d",  sizeof(*p));    getchar();    return 0; } 
  • 200
  • 4
  • 800
  • 80

Question 3

C
#include <stdio.h> int main() {     int a[5] = {1,2,3,4,5};     int *ptr = (int*)(&a+1);     printf("%d %d", *(a+1), *(ptr-1));     return 0; } 
  • 2 5
  • Garbage Value
  • Compiler Error
  • Segmentation Fault

Question 4

C
#include <stdio.h>  char *c[] = {"GeksQuiz", "MCQ", "TEST", "QUIZ"}; char **cp[] = {c+3, c+2, c+1, c}; char ***cpp = cp;  int main() {     printf("%s ", **++cpp);     printf("%s ", *--*++cpp+3);     printf("%s ", *cpp[-2]+3);     printf("%s ", cpp[-1][-1]+1);     return 0; } 
  • TEST sQuiz Z CQ
  • MCQ Quiz Z CQ
  • TEST Quiz Z CQ
  • GarbageValue sQuiz Z CQ

Question 5

Predict the output C
#include <string.h> #include <stdio.h> #include <stdlib.h>  void fun(char** str_ref) {     str_ref++; }  int main() {     char *str = (void *)malloc(100*sizeof(char));     strcpy(str, "GeeksQuiz");     fun(&str);     puts(str);     free(str);     return 0; } 
  • GeeksQuiz
  • eeksQuiz
  • Garbage Value
  • Compiler Error

Question 6

Assume that the size of int is 4. C
#include <stdio.h> void f(char**); int main() {     char *argv[] = { "ab", "cd", "ef", "gh", "ij", "kl" };     f(argv);     return 0; } void f(char **p) {     char *t;     t = (p += sizeof(int))[-1];     printf("%s\\n", t); } 
  • ab
  • cd
  • ef
  • gh

Question 7

C
 
  • 2 3 5 6

  • 2 3 4 5

  • 4 5 0 0

  • none of the above

Question 8

C
#include <stdio.h> #include <stdlib.h>  int main(void) {     int i;     int *ptr = (int *) malloc(5 * sizeof(int));      for (i=0; i<5; i++)         *(ptr + i) = i;      printf("%d ", *ptr++);     printf("%d ", (*ptr)++);     printf("%d ", *ptr);     printf("%d ", *++ptr);     printf("%d ", ++*ptr); } 
  • Compiler Error
  • 0 1 2 2 3
  • 0 1 2 3 4
  • 1 2 3 4 5

Question 9

Output of following program C
#include <stdio.h> int fun(int arr[]) {    arr = arr+1;	    printf("%d ", arr[0]); } int main(void) {    int arr[2] = {10, 20};    fun(arr);    printf("%d", arr[0]);    return 0; } 
  • Compiler Error
  • 20 10
  • 20 20
  • 10 10

Question 10

What is printed by the following C program?

C
$include <stdio.h> int f(int x, int *py, int **ppz) {   int y, z;   **ppz += 1;     z  = **ppz;   *py += 2;    y = *py;    x += 3;    return x + y + z; }   void main() {    int c, *b, **a;    c = 4;    b = &c;    a = &b;     printf( "%d", f(c,b,a));    getchar(); } 
  • 18

  • 19

  • 21

  • 22

Tags:

There are 19 questions to complete.

Take a part in the ongoing discussion