C MCQ Set-25 : Multiple Choice Questions in C Set-25

Set-26 C MCQ

  1. What will be the output of the following C code?

    #include<stdio.h>
    int main()
    {
    int i = 97, *p = &i;
    foo(&i);
    printf(“%d “, *p);
    }
    void foo(int *p)
    {
    int j = 2;
    p = &j;
    printf(“%d “, *p);
    }

    a) 2 97
    b) 2 2
    c) Compile time error
    d) Segmentation fault/code crash

Answer : A


  1. Which among the following is right?

a. sizeof(struct stemp) > sizeof(union utemp) > sizeof(char )
b. sizeof(struct stemp) < sizeof(union utemp*) < sizeof(char *)
c. sizeof(struct stemp) = sizeof(union utemp) = sizeof(char *)
d. The order Depends on the compiler

Answer : C


  1. What will be the output of the C program?

#include<stdio.h>
int main()
{
char *ptr;
char string[] = “Learn C Programming”;
ptr = string;
ptr += 6;
printf(“%s”,ptr);
return 0;
}

A. compilation error
B. Runtime error
C. Learn C Programming
D. C Programming

Answer : D


  1. What will be the output of following code:

#include<stdio.h>
int main()
{
const int a = 5;
int *ptr;
ptr = &a;
*ptr = 10;
printf(“%d\n”, a);
return 0;
}

A. Compilation error: Constant can’t be modified
B. Garbage Value
C. 10
D. 5

Answer : C


  1. What will be the output of the C program?

#include<stdio.h>
int main()
{
struct node
{
int a, b, c;
};
struct node num = {3, 5, 6};
struct node *ptr = & num;
printf(“%d\n”, *((int*)ptr + 1 + (3-2)));
return 0;
}

A. 3
B. 5
C. Compilation error
D. 6

Answer : D


  1. What will be the output of the C program?

#include<stdio.h>
int main(){
char *ptr = “Pointer in c”, arr[15];
arr[15] = *ptr;
printf(“%c”,arr[0]);
return 0;
}
A. Garbage value
B. Run time error
C. P
D. Compile time error

Answer : A
C MCQ Set-25 Explanation


  1. What is the output of following C code?

    #include<stdio.h>
    int main() {
    struct emp
    {
    char name[20];
    int age;
    float sal;
    };
    struct emp e ={“Tiger”}
    printf(“%d%d%f”,e.age,e.sal);
    }
    A:Garbage Collection
    B:Error
    C:1 0.000000
    D:0 0.000000

    Answer : D

8. What will be the output of the program ?

int main()
{
enum status {pass, fail, absent};
enum status stud1, stud2, stud3;
stud1 = pass;
stud2 = absent;
stud3 = fail;
printf(“%d %d %d\n”, stud1, stud2, stud3);
return 0;
}
A) 0, 1, 2
B) 1, 2, 3
C) 0, 2, 1
D) 1, 3, 2

Answer : C
C MCQ Set-25 Explanation


9. What will be the output of the program in Turbo C (under DOS)?

int main()
{
struct emp
{
char *n;
int age;
};
struct emp e1 = {“Dravid”, 23};
struct emp e2 = e1;
strupr(e2.n);
printf(“%s\n”, e1.n);
return 0;
}

A: Error: Invalid structure assignment
B: DRAVID
C: Dravid
D: No output

Answer : B


10. What will be the output of the following C code?

#include<stdio.h>
struct point
{
int x;
int y;
};
struct notpoint
{
int x;
int y;
};
int main()
{
struct point p = {1};
struct notpoint p1 = p;
printf(“%d\n”, p1.x);
}

a) Compile time error
b) 1
c) 0
d) Undefined

Answer : A


Spread the love

Leave a Comment

Your email address will not be published. Required fields are marked *