Bird
Raised Fist0
Cprogramming~20 mins

Structure of a C program - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
C Program Structure Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate
2:00remaining
Output of a simple C program with main function
What is the output of this C program when compiled and run?
C
#include <stdio.h>

int main() {
    printf("Hello, C world!\n");
    return 0;
}
Ahello, c world!
BHello, C world!\n
CHello, C world!
DCompilation error
Attempts:
2 left
💡 Hint
Look carefully at the exact string printed and the newline character.
❓ Predict Output
intermediate
2:00remaining
Value of variable after execution
What is the value of variable x after running this program?
C
#include <stdio.h>

int main() {
    int x = 5;
    x = x + 10;
    return 0;
}
A5
B10
CCompilation error
D15
Attempts:
2 left
💡 Hint
x starts at 5 and then 10 is added.
❓ Predict Output
advanced
2:00remaining
Output of a program with multiple functions
What is the output of this C program?
C
#include <stdio.h>

void greet() {
    printf("Hi! ");
}

int main() {
    greet();
    printf("Welcome to C programming.\n");
    return 0;
}
AHi! Welcome to C programming.\n
BHi! Welcome to C programming.
C.gnimmargorp C ot emocleW !iH
Di! Welcome to C programming.
ECompilation error
Attempts:
2 left
💡 Hint
Look at how printf handles newlines.
❓ Predict Output
advanced
2:00remaining
What error does this program produce?
What error will this C program produce when compiled?
C
#include <stdio.h>

int main() {
    int a = 10
    printf("Value: %d\n", a);
    return 0;
}
ASyntax error: missing semicolon
BNo error, prints 'Value: 10'
CRuntime error: undefined variable
DLinker error: missing main
Attempts:
2 left
💡 Hint
Check each line for missing punctuation.
🧠 Conceptual
expert
2:00remaining
Number of functions in this C program
How many functions are defined in this C program?
C
#include <stdio.h>

void first() {
    printf("First\n");
}

void second() {
    printf("Second\n");
}

int main() {
    first();
    second();
    return 0;
}
A3
B2
C4
D1
Attempts:
2 left
💡 Hint
Count all functions including main.

Practice

(1/5)
1. Which part of a C program is mandatory to start the execution of the program?
easy
A. The return statement
B. The printf() statement
C. The #include directive
D. The main() function

Solution

  1. Step 1: Understand program entry point

    In C, the program always starts executing from the main() function.
  2. Step 2: Identify mandatory part for execution

    Without main(), the program has no defined starting point.
  3. Final Answer:

    The main() function -> Option D
  4. Quick Check:

    Program starts at main() [OK]
Hint: Look for the function where execution begins [OK]
Common Mistakes:
  • Thinking printf() starts the program
  • Confusing #include with execution start
  • Assuming return starts the program
2. Which of the following is the correct way to include the standard input-output header in a C program?
easy
A. #include "stdio.h"
B. #include
C. include
D. #include stdio.h

Solution

  1. Step 1: Recognize correct syntax for header inclusion

    The standard way to include system headers is using angle brackets: #include <header>.
  2. Step 2: Check each option

    #include uses correct syntax: #include <stdio.h>. #include "stdio.h" uses quotes which is for user headers. Options C and D miss the # or angle brackets.
  3. Final Answer:

    #include <stdio.h> -> Option B
  4. Quick Check:

    System headers use <> brackets [OK]
Hint: Use #include with angle brackets for standard headers [OK]
Common Mistakes:
  • Using quotes instead of angle brackets for standard headers
  • Omitting the # symbol
  • Missing angle brackets or quotes
3. What will be the output of the following C program?
#include <stdio.h>

int main() {
    printf("Hello, World!\n");
    return 0;
}
medium
A. Hello World
B. hello, world!
C. Hello, World!
D. Syntax Error

Solution

  1. Step 1: Analyze the printf statement

    The program prints exactly the string inside quotes: "Hello, World!\n" which means it prints Hello, World! followed by a new line.
  2. Step 2: Check for case and punctuation

    The output matches Hello, World! exactly, including capitalization and punctuation.
  3. Final Answer:

    Hello, World! -> Option C
  4. Quick Check:

    Output matches printf string exactly [OK]
Hint: Match output exactly with printf string [OK]
Common Mistakes:
  • Ignoring case sensitivity
  • Missing punctuation or newline
  • Assuming syntax error without checking code
4. Identify the error in the following C program:
#include <stdio.h>

int main() {
    printf("Welcome to C programming!");
}
medium
A. Missing return statement in main function
B. Missing semicolon after printf statement
C. Incorrect header file included
D. No error, program is correct

Solution

  1. Step 1: Check syntax of printf statement

    The printf line ends with a semicolon, so no syntax error there.
  2. Step 2: Check main function return

    The main function is declared to return int but lacks a return statement, which can cause a warning or error depending on compiler settings.
  3. Final Answer:

    Missing return statement in main function -> Option A
  4. Quick Check:

    main() must return int value [OK]
Hint: Always include return 0; in main() [OK]
Common Mistakes:
  • Assuming missing semicolon error
  • Ignoring missing return in main
  • Thinking header file is wrong
5. You want to write a C program that prints numbers from 1 to 5 using a loop inside the main() function. Which of the following code snippets correctly shows the structure of such a program?
hard
A. #include int main() { int i; for(i = 1; i <= 5; i++) { printf("%d\n", i); } return 0; }
B. #include void main() { int i; for(i = 1; i < 5; i++) { printf("%d\n", i); } }
C. #include int main() { int i = 1; while(i < 5) { printf("%d\n", i); i++; } return 0; }
D. #include int main() { int i; for(i = 1; i <= 5; i++) printf("%d\n", i); }

Solution

  1. Step 1: Check loop range and printing

    #include int main() { int i; for(i = 1; i <= 5; i++) { printf("%d\n", i); } return 0; } uses a for loop from 1 to 5 inclusive, printing each number with newline, which matches the requirement.
  2. Step 2: Verify program structure and correctness

    #include int main() { int i; for(i = 1; i <= 5; i++) { printf("%d\n", i); } return 0; } has correct int main(), includes return 0;, and proper syntax. Other options have issues: B uses void main() (not standard), loop range is incorrect; C loops only to 4; D misses braces which is allowed but less clear.
  3. Final Answer:

    Option A is the correct and complete program structure -> Option A
  4. Quick Check:

    Correct loop and main() structure [OK]
Hint: Use int main() with return 0 and correct loop range [OK]
Common Mistakes:
  • Using void main() instead of int main()
  • Incorrect loop range (less than 5)
  • Omitting return statement
  • Missing braces causing confusion
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard