Bird
Raised Fist0
Cprogramming~20 mins

What is C - Practice Questions & Exercises

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
C Language Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
1:30remaining
What is the primary use of the C programming language?

Which of the following best describes the main purpose of the C programming language?

AA scripting language used for automating tasks.
BA high-level language mainly used for web development.
CA low-level language used for system programming and embedded systems.
DA language designed exclusively for database management.
Attempts:
2 left
💡 Hint

Think about what kind of programs need direct hardware access and efficiency.

❓ Predict Output
intermediate
1:00remaining
Output of a simple C program

What is the output of the following C program?

C
#include <stdio.h>

int main() {
    int a = 5, b = 3;
    printf("%d\n", a + b);
    return 0;
}
A8
B53
C0
DError: invalid syntax
Attempts:
2 left
💡 Hint

Remember that the + operator adds numbers, not concatenates them.

❓ Predict Output
advanced
1:30remaining
What is the output of pointer manipulation?

What will this C program print?

C
#include <stdio.h>

int main() {
    int x = 10;
    int *p = &x;
    *p = 20;
    printf("%d\n", x);
    return 0;
}
ACompilation error
BAddress of x
C10
D20
Attempts:
2 left
💡 Hint

Changing the value pointed to by p changes x.

🔧 Debug
advanced
1:30remaining
Identify the error in this C code snippet

What error will this C code produce?

C
#include <stdio.h>

int main() {
    int arr[3] = {1, 2, 3};
    printf("%d\n", arr[3]);
    return 0;
}
AUndefined behavior (accessing out of bounds)
BCompilation error
CPrints 3
DPrints 0
Attempts:
2 left
💡 Hint

Array indices start at 0 and go up to size-1.

🧠 Conceptual
expert
2:00remaining
Why is C considered a 'portable' language?

Which reason best explains why C is called a portable programming language?

ABecause C code can run without any changes on all hardware architectures.
BBecause C compilers exist for many platforms, allowing code to be recompiled easily.
CBecause C programs do not use any hardware-specific features.
DBecause C automatically translates code to machine language for any device.
Attempts:
2 left
💡 Hint

Think about how code moves between different computers.

Practice

(1/5)
1. What is C primarily known as?
easy
A. An operating system
B. A type of database
C. A web design tool
D. A fast and basic programming language

Solution

  1. Step 1: Understand the nature of C

    C is a programming language used to write software.
  2. Step 2: Identify its key features

    C is known for being fast and basic, making it popular for many applications.
  3. Final Answer:

    A fast and basic programming language -> Option D
  4. Quick Check:

    C = fast, basic language [OK]
Hint: Remember C is a programming language, not a tool or system [OK]
Common Mistakes:
  • Confusing C with a database
  • Thinking C is for web design
  • Mixing C with operating systems
2. Which of the following is the correct way to start a C program?
easy
A. void start() {}
B. int main() {}
C. function main() {}
D. begin() {}

Solution

  1. Step 1: Recall C program entry point

    In C, the program starts execution from the main function.
  2. Step 2: Identify correct syntax

    The correct syntax is int main() {} which returns an integer.
  3. Final Answer:

    int main() {} -> Option B
  4. Quick Check:

    Program starts at main() [OK]
Hint: Look for int main() as program start [OK]
Common Mistakes:
  • Using void instead of int for main
  • Using non-C syntax like function keyword
  • Using undefined start or begin functions
3. What will be the output of this C program?
#include <stdio.h>
int main() {
    printf("Hello, C!\n");
    return 0;
}
medium
A. Hello, C!
B. Hello, C!\n
C. printf("Hello, C!\n");
D. Error: missing semicolon

Solution

  1. Step 1: Understand printf output

    The printf function prints the string inside quotes to the screen.
  2. Step 2: Interpret escape sequence

    The \n adds a new line but does not print literally.
  3. Final Answer:

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

    printf prints string with newline [OK]
Hint: Remember \n means new line, not printed text [OK]
Common Mistakes:
  • Thinking \n prints as text
  • Confusing code with output
  • Assuming syntax error without cause
4. Find the error in this C code:
#include <stdio.h>
int main() {
    printf("Welcome to C programming")
    return 0;
}
medium
A. main function should return void
B. Wrong header file included
C. Missing semicolon after printf statement
D. printf syntax is incorrect

Solution

  1. Step 1: Check syntax of printf line

    The printf statement must end with a semicolon.
  2. Step 2: Identify missing semicolon

    Here, the semicolon after printf(...) is missing causing a syntax error.
  3. Final Answer:

    Missing semicolon after printf statement -> Option C
  4. Quick Check:

    Semicolon missing after printf [OK]
Hint: Look for missing semicolons after statements [OK]
Common Mistakes:
  • Thinking header file is wrong
  • Assuming main returns void
  • Believing printf syntax is wrong
5. You want to write a C program that prints numbers 1 to 3 using a for loop in main. Which code snippet correctly does this?
hard
A. #include <stdio.h> int main() { for(int i=1; i<=3; i++) printf("%d ", i); return 0; }
B. #include <stdio.h> int main() { printf("1 2 3\n"); return 0; }
C. #include <stdio.h> void main() { printf("1 2 3\n"); }
D. #include <stdio.h> int main() { print("1 2 3\n"); return 0; }

Solution

  1. Step 1: Check program structure and output

    #include <stdio.h> int main() { for(int i=1; i<=3; i++) printf("%d ", i); return 0; } uses a loop to print numbers 1 to 3 with correct syntax.
  2. Step 2: Verify correctness of other options

    The hardcoded printf prints numbers but not using a loop; the void main version is not standard; the print instead of printf causes an error.
  3. Final Answer:

    for(int i=1; i<=3; i++) printf("%d ", i); -> Option A
  4. Quick Check:

    Loop with printf prints 1 2 3 [OK]
Hint: Use for loop with printf to print sequence [OK]
Common Mistakes:
  • Using void main instead of int main
  • Using print instead of printf
  • Not using loop for multiple prints
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