Challenge - 5 Problems
Constants and Literals Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of integer and floating-point constants
What is the output of this C program?
#include <stdio.h>
int main() {
const int a = 5;
const float b = 3.0f;
printf("%d %.1f\n", a, b);
return 0;
}C
#include <stdio.h> int main() { const int a = 5; const float b = 3.0f; printf("%d %.1f\n", a, b); return 0; }
Attempts:
2 left
💡 Hint
Look at the format specifiers used in printf.
✗ Incorrect
The integer constant 'a' is printed with %d showing 5, and the float constant 'b' is printed with %.1f showing 3.0.
❓ Predict Output
intermediate2:00remaining
Output of character and string literals
What will this C program print?
#include <stdio.h>
int main() {
const char c = 'A';
const char *s = "Hello";
printf("%c %s\n", c, s);
return 0;
}C
#include <stdio.h> int main() { const char c = 'A'; const char *s = "Hello"; printf("%c %s\n", c, s); return 0; }
Attempts:
2 left
💡 Hint
Remember that '%c' prints a single character and '%s' prints a string.
✗ Incorrect
The character constant 'A' prints as 'A', and the string literal "Hello" prints as Hello.
❓ Predict Output
advanced2:00remaining
Output of octal and hexadecimal integer constants
What is the output of this C program?
#include <stdio.h>
int main() {
int x = 010; // octal 10
int y = 0x10; // hex 10
printf("%d %d\n", x, y);
return 0;
}C
#include <stdio.h> int main() { int x = 010; // octal 10 int y = 0x10; // hex 10 printf("%d %d\n", x, y); return 0; }
Attempts:
2 left
💡 Hint
Octal 010 is 8 in decimal, hex 0x10 is 16 in decimal.
✗ Incorrect
The octal constant 010 equals decimal 8, and the hexadecimal constant 0x10 equals decimal 16.
❓ Predict Output
advanced2:00remaining
Output of escape sequences in character constants
What does this C program print?
#include <stdio.h>
int main() {
char c1 = '\n';
char c2 = '\t';
printf("%d %d\n", c1, c2);
return 0;
}C
#include <stdio.h> int main() { char c1 = '\n'; char c2 = '\t'; printf("%d %d\n", c1, c2); return 0; }
Attempts:
2 left
💡 Hint
Escape sequences represent special ASCII codes.
✗ Incorrect
The newline '\n' is ASCII 10, and tab '\t' is ASCII 9.
❓ Predict Output
expert2:00remaining
Value of a floating-point constant with suffix
What is the output of this C program?
#include <stdio.h>
int main() {
double d = 1.5;
float f = 1.5f;
printf("%.1f %.1f\n", d, f);
return 0;
}C
#include <stdio.h> int main() { double d = 1.5; float f = 1.5f; printf("%.1f %.1f\n", d, f); return 0; }
Attempts:
2 left
💡 Hint
The suffix 'f' makes the constant a float, but printing with %.1f shows the value.
✗ Incorrect
Both variables hold the value 1.5; the suffix 'f' just sets the type to float.