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

Set-26 C MCQ

1. Assume that size of an integer is 32 bit. What is the output of following program?

#include<stdio.h>
struct st
{
int x;
static int y;
};

int main()
{
printf(“%d”, sizeof(struct st));
return 0;
}
(A) 4
(B) 8
(C) Compiler Error
(D) Runtime Error

Answer: (C)


2. Which of the following structure definitions are correct?

I. struct book
{
int a;
struct book b;
};

II. struct book
{
int a;
struct book *next;
}

III. struct book
{
int book_Id;
char title=”C Programming”;
float price;
}

a. only I
b. only II
c. Both I and II
d. All of them

Answer: B


3. Which of the following cannot be a structure member?

A. Another structure
B. Function
C. Array
D. None of the mentioned

Answer : B


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

#include<stdio.h>
struct student
{
char *name;
};
void main()
{
struct student s, m;
s.name = “st”;
m = s;
printf(“%s%s”, s.name, m.name);
}
a) Compile time error
b) Nothing
c) Junk values
d) st st

Answer : D


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

#include<stdio.h>
struct point
{
int x;
int y;
};
int main()
{
struct point p = {1};
struct point p1 = {1};
if(p == p1)
printf(“equal\n”);
else
printf(“not equal\n”);
}

a) Compile time error
b) equal
c) depends on the standard
d) not equal

Answer : A


6. Which of the following statements are correct about the program below?

#include<stdio.h>
int main()
{
char str[20], s; printf(“Enter a string\n”); scanf(“%s”, str); s=str; while(s != ‘\0’)
{
if(*s >= 97 && *s <= 122)
*s = *s-32;
s++;
}
printf(“%s”,str);
return 0;
}

a) The code converts a string in to an integer
b) The code converts lower case character to upper case
c) The code converts upper case character to lower case
d) Error in code

Answer : B


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

#include<stdio.h>
int main()
{
char *str = “hello, world\n”;
printf(“%d”, strlen(str));

}

a) Compilation error
b) Undefined behaviour
c) 13
d) 11

Answer : C
C MCQ Set-24 Explanation


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

#include<stdio.h>
void main()
{
char *str = “”;
do
{
printf(“hello”);
} while (str);
}

a) Nothing
b) Run time error
c) Varies
d) Hello is printed infinite times

Answer : D
C MCQ Set-24 Explanation


9. What will be the output of following code

#include<stdio.h>
#include<string.h>
int main()
{
char a[]={‘W’,’E’,’L’,’C’,’O’,’M’,’E’,’\0’,’D’,’E’,’A’,’R’,’\0’};
printf(“String is : %s and Length=%d”, a, strlen(a));
return 0;
}

a) String is: WELCOMEDEAR and Length=11
b) String is: WELCOME and Length=11
c) String is: WELCOME and Length=7
d) String is: WELCOMEDEAR and Length=7

Answer : C


10. What will be the output of following code:

#include<stdio.h>
#include<string.h>
int main()
{
char str1[15];
char str2[15];
int m;
strcpy(str1, “abcdef”);
strcpy(str2, “ABCDEF”);
m= strcmpi(str1, str2);
if(m< 0) printf(“str1 is not greater than str2”); else if(m> 0)
printf(“str2 is is not greater than str1”);
else
printf(“both are equal”);
return 0;
}

a) str1 is not greater than str2
b) str2 is not greater than str1
c) both are equal
d) error in given code

Answer : C


Spread the love

Leave a Comment

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