Explore topic-wise MCQs in C Programming.

This section includes 151 Mcqs, each offering curated multiple-choice questions to sharpen your C Programming knowledge and support exam preparation. Choose a topic below to get started.

1.

The library function used to reverse a string is

A. strstr()
B. strrev()
C. revstr()
D. strreverse()
Answer» C. revstr()
2.

If and bytes size, What will be the output of the program ?

A. 1, 2, 4
B. 1, 4, 4
C. 2, 2, 4
D. 2, 4, 8
Answer» C. 2, 2, 4
3.

For the following statements will and fetch the same character?

A. Yes
B. No
Answer» B. No
4.

Which of the following statements are correct about the below declarations?

A. 1, 2
B. 2, 3, 4
C. 3, 4
D. 2, 3
Answer» C. 3, 4
5.

Is there any difference between the two statements?

A. Yes
B. No
Answer» B. No
6.

If the two strings are identical, then function returns

A. -1
B. 1
C. 0
D. Yes
Answer» D. Yes
7.

What will be the output of the following C code?
#include <stdio.h>
int main()
{
char *s = "hello, Interveiw, Mania n";
printf("%d", strlen(s));

}

A. hello
B. Interveiw, Mania
C. 24
D. Compilation Error
E. None of these
Answer» D. Compilation Error
8.

What will be the output of the following C code?
#include <stdio.h>
#include <string.h>
int main()
{
char *s = "hello, Interview, Mania";
char s1[25];
strncpy(s1, s, 25);
printf("%s %d", s1, strlen(s1));
}

A. Segmentation fault
B. Compilation Error
C. Nothing
D. hello, Interview, Mania 23
E. None of these
Answer» E. None of these
9.

What will be the output of the following C code?
#include <stdio.h>
int main()
{
char s[11] = "hello";
char *s1 = " Interview Mania";
strncat(s, s1, 10);
printf("%s", s);
}

A. hello
B. Interview Mania
C. hello Interview Mania
D. hello Interview
E. None of these
Answer» D. hello Interview
10.

What will be the output of the following C code?
#include <stdio.h>
int main()
{
char s[15] = "Interview";
char *s1 = " Mania";
strcat(s, s1);
printf("%s %d", s, s[15]);
}

A. Interview
B. Interview Mania 0
C. Mania
D. Compilation Error
E. None of these
Answer» C. Mania
11.

What will be the output of the following C code?
#include <stdio.h>
int main()
{
char s[15] = "INTERVIEW";
char *ptr = strrchr(s, 'R');
printf("%c n", *(++ptr));
}

A. R
B. Compilation Error
C. V
D. Garbage value
E. None of these
Answer» D. Garbage value
12.

What will be the value of var for the following C statement?
var = strcmp("Hello", "World");

A. strcmp has void return-type
B. 1
C. 0
D. -1
E. None of these
Answer» E. None of these
13.

What will be the output of the following C code?
#include <stdio.h>
int main()
{
char n = '25';
if (isdigit(n))
{
printf("Digit n");
}
else
{
printf("Not Digit n");
}
return 0;
}

A. Compilation Error
B. 25
C. Digit
D. Not Digit
E. None of these
Answer» D. Not Digit
14.

What will be the output of the following C code?
#include <stdio.h>
#include <ctype.h>
int main()
{
int n = 'B';
if (isdigit(n))
{
printf("Digit n");
}
else
{
printf("Not Digit n");
}
return 0;
}

A. B
B. Not Digit
C. Compilation Error
D. Digit
E. None of these
Answer» C. Compilation Error
15.

What will be the output of the following C code?
#include <stdio.h>
#include <ctype.h>
int main()
{
char n = 20;
if (isdigit(n))
{
printf("Digit n");
}
else
{
printf("Not Digit n");
}
return 0;
}

A. 20
B. Digit
C. Compilation Error
D. Not Digit
E. None of these
Answer» E. None of these
16.

The following C expression can be substituted for?
if (isalpha(c) && isdigit(c))

A. if (isalphanum(c))
B. if (isalphanumeric(c))
C. if (isalnum(c))
D. All of above
E. None of these
Answer» F.
17.

Which is true about isalnum(ch), where ch is an int that can be represented as an unsigned?
 char or EOF.isalnum(ch) returns

A. Nothing
B. 0 if not isalpha(ch) or not isdigit(ch)
C. Non-zero if isalpha(ch) or isdigit(ch)
D. Both 0 if not isalpha(ch) or not isdigit(ch) & Non-zero if isalpha(ch) or isdigit(ch)
E. None of these
Answer» E. None of these
18.

Which is true about isupper(ch), where ch is an int that can be represented as an unsigned?
char or EOF.isupper(ch) returns

A. 0 if ch is not upper case
B. Non-zero if ch is upper case
C. Both 0 if ch is not upper case & Non-zero if ch is upper case
D. Nothing
E. None of these
Answer» D. Nothing
19.

Which is true about isaplpha(ch), where ch is an int that can be represented as an unsigned?
char or EOF.isalpha(ch) returns

A. 0 if ch is not alphabetic
B. Non-zero if ch is alphabetic
C. Both 0 if ch is not alphabetic & Non-zero if ch is alphabetic
D. Non-zero if d is alphabetic
E. None of these
Answer» D. Non-zero if d is alphabetic
20.

What will be the output of the following C code?
#include <stdio.h>
#include <ctype.h>
int main()
{
int n = ' ';
if (isspace(n))
{
printf("Space n");
}
else
{
printf("Not Space n");
}
return 0;
}

A. Compilation Error
B. Space
C. Garbage value
D. Not Space
E. None of these
Answer» C. Garbage value
21.

What will be the output of the following C code?
#include <stdio.h>
#include <ctype.h>
int main()
{
int num = 15;
if (isspace(num))
{
printf("Space n");
}
else
{
printf("Not Space n");
}
return 0;
}

A. Compilation Error
B. 15
C. Not Space
D. Space
E. None of these
Answer» D. Space
22.

What will be the output of the following C code?
#include <stdio.h>
int main()
{
char *s = "Interview, Mania";
char s1[20] = "hello Interview Mania";
strcpy(s, s1);
printf("%s", s1);
}

A. Segmentation fault
B. Compilation Error
C. Interview, Mania
D. hello Interview Mania
E. None of these
Answer» B. Compilation Error
23.

What will be the output of the following C code?
#include <stdio.h>
int main()
{
char *s = "Interview, Mania";
char *s1 = "Interview, Mania";
if (strcmp(s, s1))
{
printf("Equal");
}
else
{
printf("Not Equal");
}
}

A. Compilation Error
B. Equal
C. Garbage value
D. Not Equal
E. None of these
Answer» E. None of these
24.

Read the following program.
findPalindrome
{
char *str;
char *str1;
str = str1;
while(str1 != NULL) { str1++; }
while(str!=NULL)
{ if(str1--!= str++) { printf("Not palindrome"); return }
}
printf("Palindrome");
}
This function will work correctly for which string?

A. even palindrome
B. odd palindrome
C. both even and odd
D. none of the above
Answer» D. none of the above
25.

What will be the output of the following C code?
#include <stdio.h>
#include <ctype.h>
int main()
{
char ch = 'I';
printf("is : %c n", tolower('W'));
}

A. I
B. Compilation Error
C. is : w
D. W
E. None of these
Answer» D. W
26.

What will be the output of the following C code?
#include <stdio.h>
#include <ctype.h>
int main()
{
char ch = 'I';
printf("%d n", isspace(ch));
}

A. I
B. Compilation Error
C. Non-zero number
D. Nothing
E. None of these
Answer» D. Nothing
27.

Which of the following is correct way to convert a String to an int? String s = "123"; int i; i = (int)s; String s = "123"; int i; i = int.Parse(s); String s = "123"; int i; i = Int32.Parse(s); String s = "123"; int i; i = Convert.ToInt32(s); String s = "123"; int i; i = CInt(s);

A. 1, 3, 5
B. 2, 4
C. 3, 5
D. 2, 3, 4
Answer» E.
28.

Which of the following snippets are the correct way to convert a Single into a String? Single f = 9.8f; String s; s = (String) (f); Single f = 9.8f; String s; s = Convert.ToString(f); Single f = 9.8f; String s; s = f.ToString(); Single f = 9.8f; String s; s = Clnt(f); Single f = 9.8f; String s; s = CString(f);

A. 1, 2
B. 2, 3
C. 1, 3, 5
D. 2, 4
Answer» C. 1, 3, 5
29.

Which of the following statements are correct about the String Class in C#.NET? Two strings can be concatenated by using an expression of the form s3 = s1 + s2; String is a primitive in C#.NET. A string built using StringBuilder Class is Mutable. A string built using String Class is Immutable. Two strings can be concatenated by using an expression of the form s3 = s1&s2;

A. 1, 2, 5
B. 2, 4
C. 1, 3, 4
D. 3, 5
Answer» D. 3, 5
30.

If s1 and s2 are references to two strings then which of the following are the correct ways to find whether the contents of the two strings are equal? if(s1 = s2) if(s1 == s2) int c; c = s1.CompareTo(s2); if( strcmp(s1, s2) ) if (s1 is s2)

A. 1, 2
B. 2, 3
C. 4, 5
D. 3, 5
Answer» C. 4, 5
31.

Which of the following statements are true about the C#.NET code snippet given below? String s1, s2; s1 = "Hi"; s2 = "Hi";String objects cannot be created without using new. Only one object will get created. s1 and s2 both will refer to the same object. Two objects will get created, one pointed to by s1 and another pointed to by s2. s1 and s2 are references to the same object.

A. 1, 2, 4
B. 2, 3, 5
C. 3, 4
D. 2, 5
Answer» C. 3, 4
32.

Which of the following statements are correct? String is a value type. String literals can contain any character literal including escape sequences. The equality operators are defined to compare the values of string objects as well as references. Attempting to access a character that is outside the bounds of the string results in an IndexOutOfRangeException. The contents of a string object can be changed after the object is created.

A. 1, 3
B. 3, 5
C. 2, 4
D. 1, 2, 4
Answer» D. 1, 2, 4
33.

If the size of pointer is 32 bits What will be the output of the program ?_x000D_ #include_x000D_ _x000D_ int main()_x000D_ {_x000D_ char a[] = "Visual C++";_x000D_ char *b = "Visual C++";_x000D_ printf("%d, %d\n", sizeof(a), sizeof(b));_x000D_ printf("%d, %d", sizeof(*a), sizeof(*b));_x000D_ return 0;_x000D_ }

A. 10, 22, 2
B. 10, 41, 2
C. 11, 41, 1
D. 12, 22, 2
Answer» D. 12, 22, 2
34.

Which of the following statements are correct about the below declarations?_x000D_ char *p = "Sanjay";char a[] = "Sanjay";_x000D_ _x000D_ _x000D_ 1:_x000D_ There is no difference in the declarations and both serve the same purpose._x000D_ _x000D_ _x000D_ 2:_x000D_ p is a non-const pointer pointing to a non-const string, whereas a is a const pointer pointing to a non-const pointer._x000D_ _x000D_ _x000D_ 3:_x000D_ The pointer p can be modified to point to another string, whereas the individual characters within array a can be changed._x000D_ _x000D_ _x000D_ 4:_x000D_ In both cases the '\0' will be added at the end of the string "Sanjay".

A. 1, 2
B. 2, 3, 4
C. 3, 4
D. 2, 3
Answer» C. 3, 4
35.

What will be the output of the program ?_x000D_ #include_x000D_ _x000D_ int main()_x000D_ {_x000D_ char *names[] = { "Suresh", "Siva", "Sona", "Baiju", "Ritu"};_x000D_ int i;_x000D_ char *t;_x000D_ t = names[3];_x000D_ names[3] = names[4];_x000D_ names[4] = t;_x000D_ for(i=0; i<=4; i++)_x000D_ printf("%s,", names[i]);_x000D_ return 0;_x000D_ }

A. Suresh, Siva, Sona, Baiju, Ritu
B. Suresh, Siva, Sona, Ritu, Baiju
C. Suresh, Siva, Baiju, Sona, Ritu
D. Suresh, Siva, Ritu, Sona, Baiju
Answer» C. Suresh, Siva, Baiju, Sona, Ritu
36.

Which of the following statements are correct about the program below? #include 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++; }_x000D_ 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» C. The code converts upper case character to lower case
37.

What will be the output of the program ?_x000D_ #include_x000D_ _x000D_ int main()_x000D_ {_x000D_ char str[] = "Nagpur";_x000D_ str[0]='K';_x000D_ printf("%s, ", str);_x000D_ str = "Kanpur";_x000D_ printf("%s", str+1);_x000D_ return 0;_x000D_ }

A. Kagpur, Kanpur
B. Nagpur, Kanpur
C. Kagpur, anpur
D. Error
Answer» E.
38.

What will be the output of the program ?_x000D_ #include_x000D_ _x000D_ int main()_x000D_ {_x000D_ static char mess[6][30] = {"Don't walk in front of me...", _x000D_ "I may not follow;", _x000D_ "Don't walk behind me...", _x000D_ "Just walk beside me...", _x000D_ "And be my friend." };_x000D_ _x000D_ printf("%c, %c\n", *(mess[2]+9), *(*(mess+2)+9));_x000D_ return 0;_x000D_ }

A. t, t
B. k, k
C. n, k
D. m, f
Answer» C. n, k
39.

What will be the output of the program ?_x000D_ #include_x000D_ _x000D_ int main()_x000D_ {_x000D_ char p[] = "%d\n";_x000D_ p[1] = 'c';_x000D_ printf(p, 65);_x000D_ return 0;_x000D_ }

A. A
B. a
C. c
D. 65
Answer» B. a
40.

What will be the output of the program ?_x000D_ #include_x000D_ _x000D_ int main()_x000D_ {_x000D_ int i;_x000D_ char a[] = "\0";_x000D_ if(printf("%s", a))_x000D_ printf("The string is empty\n");_x000D_ else_x000D_ printf("The string is not empty\n");_x000D_ return 0;_x000D_ }

A. The string is empty
B. The string is not empty
C. No output
D. 0
Answer» C. No output
41.

For the following statements will arr[3] and ptr[3] fetch the same character?_x000D_ char arr[] = "IndiaBIX";char *ptr = "IndiaBIX";

A. Yes
B. No
Answer» B. No
42.

Determine output:public class Test{public static void main(String args[]){String str = null;if(str.length() == 0){System.out.print("1");}else if(str == null){System.out.print("2");}else{System.out.print("3");}}}

A. ompilation fails.
B. 1" is printed.
C. 2" is printed.
D. 3" is printed.
E. n exception is thrown at runtime.
Answer» F.
43.

What will be the output?1. public class Test{2.public static void main(String args[]){3.Object myObj = new String[]{"one", "two", "three"};4.{5.for(String s : (String[])myObj)6.System.out.print(s + ".");7.}8.}9. }

A. ne.two.three.
B. ompilation fails because of an error at line 3
C. ompilation fails because of an error at line 5
D. n exception is thrown at runtime.
E. one of these
Answer» B. ompilation fails because of an error at line 3
44.

What will be the output of the following program code?public class Test{public static void main(String args[]){String s = "what";StringBuffer sb = new StringBuffer("what");System.out.print(sb.equals(s)+","+s.equals(sb));}}

A. rue,true
B. alse,true
C. rue,false
D. alse,false
E. one of these
Answer» E. one of these
45.

What will be output?String S1 = "S1 ="+ "123"+"456";String S2 = "S2 ="+(123+456);

A. 1=123456, S2=579
B. 1=123456,S2=123456
C. 1=579,S2=579
D. one of This
Answer» B. 1=123456,S2=123456
46.

What will be the output?public class Test{public static void main (String[] args){String test = "a1b2c3";String[] tokens = test.split("\\d");for(String s: tokens)System.out.print(s);}}

A. bc
B. 23
C. untime exception thrown
D. ompilation error
Answer» B. 23
47.

What will be the output of the following program?public class Test{public static void main(String args[]){String str1 = "one";String str2 = "two";System.out.println(str1.concat(str2));}}

A. ne
B. wo
C. netwo
D. woone
E. one of these
Answer» D. woone
48.

What will be the output?String str1 = "abcde";System.out.println(str1.substring(1, 3));

A. bc
B. c
C. cd
D. bcd
E. one of these
Answer» C. cd
49.

The String method compareTo() returns

A. rue
B. alse
C. n int value
D.
Answer» D.
50.

toString() method is defined in

A. ava.lang.String
B. ava.lang.Object
C. ava.lang.util
D. one of these
Answer» C. ava.lang.util