LearnFrenzy
Sign in Take a free test

Strings · Exercise 2 of 4

Strings Predict the Output

  • 12 questions
  • Page 1 of 2
  • Answers explained
0Attempted
0Correct
0Wrong
Directions

Read each program and choose what it prints. Every program was compiled and run, so the answers are the real output. Assume a 64-bit system.

Question 1 Medium

What is the output of the following C program?

main.c
#include <stdio.h>
#include <string.h>

int main(void) {
    char s[] = "ab\0cd";
    printf("%zu %zu\n", sizeof s, strlen(s));
    return 0;
}
A 5 5
B 6 5
C 6 2
D 3 2
Question page & discussion
Question 2 Easy

What is the output of the following C program?

main.c
#include <stdio.h>

int main(void) {
    char c = 'A' + 2;
    printf("%c %d %c\n", c, c - 'A', c + 32);
    return 0;
}
A C 67 c
B B 2 b
C C 2 c
D C 2 C
Question page & discussion
Question 3 Medium

What is the output of the following C program?

main.c
#include <stdio.h>

int main(void) {
    int n = printf("Hello\n");
    printf("%d\n", n);
    return 0;
}
A Hello 5
B Hello 1
C Hello 6
D Hello 0
Question page & discussion
Question 4 Easy

What is the output of the following C program?

main.c
#include <stdio.h>

int main(void) {
    const char *s = "pointer";
    printf("[%s] %c [%s]\n", s + 3, s[1], s + 7);
    return 0;
}
A [inter] o [r]
B [nter] p []
C [nter] o [r]
D [nter] o []
Question page & discussion
Question 5 Medium

What is the output of the following C program?

main.c
#include <stdio.h>
#include <string.h>

int main(void) {
    printf("%d %d %d\n",
           strcmp("Zebra", "apple") < 0,
           strcmp("abc", "ab") > 0,
           strcmp("10", "9") < 0);
    return 0;
}
A 0 1 0
B 0 1 1
C 1 1 1
D 1 0 1
Question page & discussion
Question 6 Hard

What is the output of the following C program?

main.c
#include <stdio.h>
#include <string.h>

int main(void) {
    char line[] = "a,,b,c";
    int n = 0;
    for (char *t = strtok(line, ","); t != NULL; t = strtok(NULL, ","))
        n++;
    printf("%d %s\n", n, line);
    return 0;
}
A 4 a,,b,c
B 3 a,,b,c
C 3 a
D 4 a
Question page & discussion
Question 7 Easy

What is the output of the following C program?

main.c
#include <stdio.h>

int main(void) {
    printf("[%6s][%-6s][%.3s]\n", "C", "C", "LearnFrenzy");
    return 0;
}
A [C ][ C][Lea]
B [ C][C ][LearnF]
C [ C][C ][Lea]
D [C][C][Lea]
Question page & discussion
Question 8 Medium

What is the output of the following C program?

main.c
#include <stdio.h>
#include <string.h>

int main(void) {
    const char *msg = "Learn" "Frenzy" " 2026";
    printf("%s %zu\n", msg, strlen(msg));
    return 0;
}
A LearnFrenzy 2026 16
B Learn 5
C LearnFrenzy 2026 18
D Compilation error
Question page & discussion
Question 9 Easy

What is the output of the following C program?

main.c
#include <stdio.h>
#include <string.h>

int main(void) {
    char s[8] = "hi";
    printf("%zu %zu %d\n", sizeof s, strlen(s), s[5]);
    return 0;
}
A 3 2 0
B 8 2 0
C 8 2 garbage
D 8 8 0
Question page & discussion
Question 10 Easy

What is the output of the following C program?

main.c
#include <stdio.h>
#include <ctype.h>

int main(void) {
    char s[] = "c23 rocks";
    for (char *p = s; *p; p++)
        *p = (char) toupper((unsigned char) *p);
    puts(s);
    return 0;
}
A C23 rocks
B c23 ROCKS
C C23 ROCKS
D C ROCKS
Question page & discussion

Ready to test your Programming?

Timed online tests with instant scores and explanations.

Search LearnFrenzy

Esc

Quick links