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

12/13

Page

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

What is the index of the last argument in command line arguments?

Select an option to see the answer and solution.

What makes the following declaration denote?
int **ptr;

Select an option to see the answer and solution.

What will be the output of the following C code?
#include <stdio.h>
int main()
{
    foo(ary);
}
void foo(int **ary)
{
    int i = 10, k = 20, j = 30;
    int *ary[2];
    ary[0] = &i;
    ary[1] = &j;
    printf("%d\n", ary[0][1]);
}

Select an option to see the answer and solution.

What will be the output of the following C code?
#include <stdio.h>
int main()
{
    char str[] = "hello, world";
    str[5] = '.';
    printf("%s\n", str);
    return 0;
}

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;
    int *const p = &i;
    foo(&p);
    printf("%d\n", *p);
}
void foo(int **p)
{
    int j = 11;
    *p = &j;
    printf("%d\n", **p);
}

Select an option to see the answer and solution.

Which of the following arithmetic operation can be applied to pointers a and b?
(Assuming initialization as int *a = (int *)2; int *b = (int *)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()
{
    char a[10][5] = {"hi", "hello", "fellows"};
    printf("%d", sizeof(a[1]));
}

Select an option to see the answer and solution.

Comment on the following two operations.
int *a[] = {{1, 2, 3}, {1, 2, 3, 4}}; //- 1
int b[4][4] = {{1, 2, 3}, {1, 2, 3, 4}};//- 2

Select an option to see the answer and solution.

Which function is not called in the following C program?
#include <stdio.h>
void first()
{
    printf("first");
}
void second()
{
    first();
}
void third()
{
    second();
}
void main()
{
    void (*ptr)();
    ptr = third;
    ptr();
}

Select an option to see the answer and solution.

Which of the following syntax is correct for command-line arguments?

Select an option to see the answer and solution.

What is the correct way to declare and assign a function pointer?
(Assuming the function to be assigned is "int multi(int, int);")

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 = 5;
    char name[20];
};
void main()
{
    struct student s;
    s.no = 8;
    printf("hello");
}

Select an option to see the answer and solution.

What type of array is generally generated in Command-line argument?

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 i);
int (*foo)(int) = myfoo;
int main()
{
    f(foo(10));
}
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.

What will be the output of the following C code?
#include <stdio.h>
void fun(char *k)
{
    printf("%s", k);
}
void main()
{
    char s[] = "hello";
    fun(s);
}

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 = 0, j = 1;
    int *a[] = {&i, &j};
    printf("%d", *a[0]);
    return 0;
}

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 *ptr, a = 10;
    ptr = &a;
    *ptr += 1;
    printf("%d,%d/n", *ptr, a);
}

Select an option to see the answer and solution.

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

Select an option to see the answer and solution.

Comment on the following two operations.
int *a[] = {{1, 2, 3}, {1, 2, 3, 4}}; //- 1
int b[][] = {{1, 2, 3}, {1, 2, 3, 4}}; //- 2

Select an option to see the answer and solution.

Which of the following is a correct syntax to pass a Function Pointer as an argument?

Select an option to see the answer and solution.