Tuesday, April 18, 2023

C Programming String Predict Output MCQs Set 3

 Predict output MCQs based on C Programming Strings

1. What is the output of the following C program?

#include <stdio.h>

int main() {

   char str1[] = "hello";

   char str2[] = "world";

   printf("%s", str1);

   printf("%s", str2);

   return 0;

}

A) helloworld

B) hello world

C) hello

   world

D) Compilation error


2. What is the output of the following C program?

#include <stdio.h>

int main() {

   char str[] = "hello";

   printf("%c", str[3]);

   return 0;

}

A) h

B) e

C) l

D) o


3. What is the output of the following C program?

#include <stdio.h>

int main() {

   char str1[] = "hello";

   char str2[] = "world";

   printf("%s", str1 + 3);

   printf("%s", str2 + 1);

   return 0;

}

A) loorld

B) loorldw

C) loworld

D) helloworld


4. What is the output of the following C program?

#include <stdio.h>

int main() {

   char str[] = "hello";

   str[2] = '\0';

   printf("%s", str);

   return 0;

}

A) hel

B) he

C) hello

D) Compilation error


5. What is the output of the following C program?

#include <stdio.h>

int main() {

   int arr[] = {2, 3, 4};

   int *p = arr;

   printf("%d", *(p + 1));

   return 0;

}

A) 2

B) 3

C) 4

D) Compilation error


Check ANSEWR here...



No comments:

Post a Comment