Wednesday, 8 November 2017

Pointers Questions in C


6.
What is the output:

#include 
void f(int *p, int *q) 

  p = q; 
  *p = 2; 

int i = 0, j = 1; 
int main() 

  f(&i, &j); 
  printf("%d %d \n", i, j); 
  getchar(); 
  return 0; 
}

A. 2 2
B. 2 5
C. 0 4
D. 0 2

Answer: D
-------------------------------------------------------------

7. 

Output ?

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)); 
   return 0;
}

A. 18
B. 19
C. 21
D. 22

Answer: 19
---------------------------------------------------------------------------------------------

8.
Output of following program?

#include
int main()
{
    int a = 12;
    void *ptr = (int *)&a;
    printf("%d", *ptr);
    getchar();
    return 0;
}

A. 12
B. Compiler Error
C. Run Time Error
D. 0

Answer: B
--------------------------------------------------------------------------------------------

9.

#include
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);
}

A. ab
B. cd
C. ef
D. gh

Answer: D
-------------------------------------------------------------------------------------------

10.
What does the following C-statement declare? [1 mark]

int ( * f) (int * ) ;


A. A function that takes an integer pointer as argument and returns an integer.
B.  A function that takes an integer as argument and returns an integer pointer.
C. A pointer to a function that takes an integer pointer as argument and returns an integer.
D. A function that takes an integer pointer as argument and returns a function pointer.

Answer: C
-----------------------------------------------------------------------------------------------
First                       Previous Next                     Last
-----------------------------------------------------------------------------------------------

More Imp Topics:







100+ Best Home Decoration Ideas For Christmas Day 2019 To Make Home Beautiful

Best gifts for Christmas Day | Greeting cards for Christmas Day | Gift your children a new gift on Christmas day This Christmas d...