• Courses
  • Tutorials
  • Jobs
  • Practice
  • Contests

C Pointer Basics

Question 31

What does the following C-statement declare? int (*f) (int*);
  • A function that takes an integer pointer as argument and returns an integer
  • A function that takes an integer as argument and returns an integer pointer
  • A pointer to a function that takes an integer pointer as argument and returns an integer
  • A function that takes an integer pointer as argument and returns a function pointer

Question 32

What is the output of this C code?
#include
void main()
{
int k=5;
int *p=&k;
int **m=&p;
printf("%d %d %d",k,*p,**m);
}
  • 5 5 5
  • 5 5 junk
  • 5 junk junk
  • Compile time error

Question 33

Consider the following declaration:
int a, *b=&a, **c=&b;
The following program fragment
a=4;
**c=5;
  • does not change the value of a
  • assigns address of c to a
  • assigns the value of b to a
  • assigns 5 to a

Question 34

The following ‘C’ statement : int * f [ ] ( ); declares:
  • A function returning a pointer to an array of integers.
  • Array of functions returning pointers to integers.
  • A function returning an array of pointers to integers.
  • An illegal statement.

Question 35

Which of the following is true with respect to Reference?
  • A reference can never be NULL
  • A reference needs an explicit dereferencing mechanism
  • A reference can be reassigned after it is established
  • A reference and pointer are synonymous

Question 36

What will be the output of following C program?
main()
{
char g[] = "geeksforgeeks";
printf("%s", g + g[6] - g[8]);
}
  • geeks
  • rgeeks
  • geeksforgeeks
  • forgeeks

Question 37

Consider the C program below. What does it print? C
# include <stdio.h>
# define swapl (a, b) tmp = a; a = b; b = tmp
void swap2 ( int a, int b)
{
        int tmp;
        tmp = a; a = b; b = tmp;
 }
void swap3 (int*a, int*b)
{
        int tmp;
        tmp = *a; *a = *b; *b = tmp;
}
int main ()
{
        int num1 = 5, num2 = 4, tmp;
        if (num1 < num2) {swap1 (num1, num2);}
        if (num1 < num2) {swap2 (num1 + 1, num2);}
        if (num1 >= num2) {swap3 (&num1, &num2);}
        printf (\"%d, %d\", num1, num2);
}
 /* Add code here. Remove these lines if not writing code */ 
  • 5, 5
  • 5, 4
  • 4, 5
  • 4, 4

Question 38

The value printed by the following program is
 

C
void f(int* p, int m)
{
    m = m + 5;
    *p = *p + m;
    return;
}
void main()
{
    int i=5, j=10;
    f(&i, j);
    printf(\"%d\", i+j);
}
  • 10
     

  • 20
     

  • 30
     

  • 40
     

Question 39

Pick the best statement for the following program snippet: 
 

C
#include <stdio.h>

int main()
{
 int var;  /*Suppose address of var is 2000 */

 void *ptr = &var;
 *ptr = 5;
 printf(\"var=%d and *ptr=%d\",var,*ptr);
             
 return 0;
}
  • It will print “var=5 and *ptr=2000”
     

  • It will print “var=5 and *ptr=5”
     

  • It will print “var=5 and *ptr=XYZ” where XYZ is some random address
     

  • Compile error
     

Question 40

What does the following program print?
 

C
#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;
}
  • 2 2
     

  • 2 1
     

  • 0 1
     

  • 0 2 
     

There are 43 questions to complete.

Last Updated :
Take a part in the ongoing discussion