Vidyalelo
C Programming · all questions

Pointer
practice.

Practice every MCQ with options. Use Show answers when you want the correct option and solution.

253

Questions

7/13

Page

Pick an option on a question to see the right answer and solution.

One of the uses for function pointers in C is . . . . . . . .

Select an option to see the answer and solution.

Comment on the following pointer declaration.
int *ptr, p;

Select an option to see the answer and solution.

What will be the output of the following C code?
#include <stdio.h>
void f(int);
void (*foo)() = f;
int main(int argc, char *argv[])
{
    foo(10);
    return 0;
}
void f(int i)
{
    printf("%d\n", i);
}

Select an option to see the answer and solution.

What will be the output of the following C code?
#include <stdio.h>
void foo(int*);
int main()
{
    int i = 10, *p = &i;
    foo(p++);
}
void foo(int *p)
{
    printf("%d\n", *p);
}

Select an option to see the answer and solution.

What will be the output of the following C code?
#include <stdio.h>
void (*(f)())(int, float);
typedef void (*(*x)())(int, float);
void foo(int i, float f);
int main()
{
    x p = f;
    p();
}
void (*(f)())(int, float)
{
    return foo;
}
void foo(int i, float f)
{
    printf("%d %f\n", i, f);
}

Select an option to see the answer and solution.

What will be the output of the following C code?
#include <stdio.h>
void main()
{
    struct student
    {
        int no;
        char name[20];
    };
    struct student s;
    s.no = 8;
    printf("%d", s.no);
}

Select an option to see the answer and solution.

What are the elements present in the array of the following C code?
int array[5] = {5};

Select an option to see the answer and solution.

What will be the output of the following C code?
#include <stdio.h>
struct student
{
    int no;
    char name[20];
};
void main()
{
    student s;
    s.no = 8;
    printf("hello");
}

Select an option to see the answer and solution.

What will be the output of the following C code?
#include <stdio.h>
void foo(float *);
int main()
{
    int i = 10, *p = &i;
    foo(&i);
}
void foo(float *p)
{
    printf("%f\n", *p);
}

Select an option to see the answer and solution.

What will be the output of the following C code?
#include <stdio.h>
void main()
{
    char *a[10] = {"hi", "hello", "how"};
    int i = 0, j = 0;
    a[0] = "hey";
    for (i = 0;i < 10; i++)
    printf("%s\n", a[i]);
}

Select an option to see the answer and solution.

What is the correct syntax to send a 3-dimensional array as a parameter? (Assuming declaration int a[5][4][3];)

Select an option to see the answer and solution.

What will be the output of the following C code?
#include <stdio.h>
void f(int a[][])
{
    a[0][1] = 3;
    int i = 0, j = 0;
    for (i = 0;i < 2; i++)
    for (j = 0;j < 3; j++)
    printf("%d", a[i][j]);
}
void main()
{
    int a[2][3] = {0};
    f(a);
}

Select an option to see the answer and solution.

Which of following logical operation can be applied to pointers?
(Assuming initialization int *a = 2; int *b = 3;)

Select an option to see the answer and solution.

What will be the output of the following C code?
#include <stdio.h>
void main()
{
    int k = 5;
    int *p = &k;
    int **m  = &p;
    printf("%d%d%d\n", k, *p, **m);
}

Select an option to see the answer and solution.

What are the different ways to initialize an array with all elements as zero?

Select an option to see the answer and solution.

What will be the output of the following C code?
#include <stdio.h>
int main()
{
    int a[4] = {1, 2, 3, 4};
    int *ptr  =  &a[2];
    float n = 1;
    ptr = ptr + n;
    printf("%d\n", *ptr);
}

Select an option to see the answer and solution.

What is the size of *ptr in a 32-bit machine (Assuming initialization as int *ptr = 10;)?

Select an option to see the answer and solution.

What will be the output of the following C code?
#include <stdio.h>
void f(int (*x)(int));
int myfoo(int);
int (*foo)() = myfoo;
int main()
{
    f(foo);
}
void f(int(*i)(int ))
{
    i(11);
}
int myfoo(int i)
{
    printf("%d\n", i);
    return i;
}

Select an option to see the answer and solution.

Comment on the following 2 arrays with respect to P and Q.
int *a1[8];
int *(a2[8]);
P. Array of pointers
Q. Pointer to an array

Select an option to see the answer and solution.

What will be the output of the following C code?
#include <stdio.h>
int main()
{
    int i = 10;
    void *p = &i;
    printf("%f\n", *(float*)p);
    return 0;
}

Select an option to see the answer and solution.