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

6/13

Page

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

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

Select an option to see the answer and solution.

Is the below declaration legal?
int* ((*x)())[2];

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 a[2][3] = {1, 2, 3, , 4, 5};
    int i = 0, j = 0;
    for (i = 0; i < 2; i++)
    for (j = 0; j < 3; j++)
    printf("%d", a[i][j]);
}

Select an option to see the answer and solution.

What will be the output of the following C code (run without any command line arguments)?
#include <stdio.h>
int main(int argc, char *argv[])
{
    while (*argv++ != NULL)
    printf("%s\n", *argv);
    return 0;
}

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 s[] = "hello";
    s++;
    printf("%c\n", *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 = 11;
    int *p = &i;
    foo(&p);
    printf("%d ", *p);
}
void foo(int *const *p)
{
    int j = 10;
    *p = &j;
    printf("%d ", **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()
{
    int k = 5;
    int *p = &k;
    int **m  = &p;
    printf("%d%d%d\n", k, *p, **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()
{
    int x = 0;
    int *ptr = &5;
    printf("%p\n", 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()
{
    char *str = "hello, world\n";
    char *strc = "good morning\n";
    strcpy(strc, str);
    printf("%s\n", strc);
    return 0;
}

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 *s = "hello";
    char *p = s;
    printf("%c\t%c", *p, s[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 **p = {"hello", "hi", "bye"};
    printf("%s", (p)[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>
struct student
{
    int no;
    char name[20];
};
struct student s;
void main()
{
    s.no = 8;
    printf("%s", s.name);
}

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 add(int a, int b)
{
    return a + b;
}
int main()
{
    int (*fn_ptr)(int, int);
    fn_ptr = add;
    printf("The sum of two numbers is: %d", (int)fn_ptr(2, 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, float);
void (*(*x)())(int, float) = f;
void ((*y)(int, float));
void foo(int i, float f);
int main()
{
    y = x();
    y(1, 2);
}
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 substitution should be made to //-Ref such that ptr1 points to variable c in the following C code?
#include <stdio.h>
int main()
{
    int a = 1, b = 2, c = 3;
    int *ptr1 = &a;
    int **sptr = &ptr1;
    //-Ref
}

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

Select an option to see the answer and solution.

Which of the following declaration are illegal?

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 ary[4] = {1, 2, 3, 4};
    printf("%d\n", *ary);
}

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 = 1, b = 2, c = 3;
    int *ptr1 = &a, *ptr2 = &b, *ptr3 = &c;
    int **sptr = &ptr1; //-Ref
    *sptr = ptr2;
}

Select an option to see the answer and solution.