Any2Quiz
Computer Science / Languages / C

Syntax Quiz - Languages C

Free practice quiz: Syntax (Languages C). 54 multiple-choice questions with answers and explanations. Play online, no sign-up needed.

Play all 54 questions free

Sample questions

  1. In C programming, which of the following is a valid way to declare an integer variable named 'count' and initialize it to 10?

    1. int count = 10;
    2. count int = 10;
    3. declare int count = 10;
    4. int count := 10;
    Show answer

    Answer: A. int count = 10;

    In C, the syntax for declaring an integer variable is 'int variable_name;'. Initialization can be done directly during declaration using the assignment operator '=', as in 'int variable_name = value;'. Option 'b' has incorrect keyword order, 'c' uses a non-existent 'declare' keyword, and 'd' uses a syntax not valid in C.

  2. What is the correct syntax for accessing an element of an array named 'arr' at index 5 in C?

    1. arr(5)
    2. arr[5]
    3. arr.5
    4. arr{5}
    Show answer

    Answer: B. arr[5]

    In C, array elements are accessed using square brackets `[]` and the index of the element. Indices are zero-based, so `arr[5]` accesses the sixth element.

  3. Which C statement is used to terminate the execution of a loop prematurely?

    1. continue
    2. return
    3. exit
    4. break
    Show answer

    Answer: D. break

    The `break` statement is used to exit a loop (`for`, `while`, `do-while`) or a `switch` statement immediately. `continue` skips the rest of the current loop iteration and proceeds to the next. `return` exits a function, and `exit` terminates the entire program.

  4. Which C operator is used for bitwise OR operation?

    1. &
    2. &&
    3. |
    4. ||
    Show answer

    Answer: C. |

    The single pipe symbol `|` is the bitwise OR operator in C. It performs an OR operation on each corresponding bit of its two operands. `||` is the logical OR operator.

  5. Which C keyword is used to explicitly return a value from a function?

    1. void
    2. return
    3. exit
    4. break
    Show answer

    Answer: B. return

    The `return` keyword is used to exit a function and optionally pass a value back to the caller. If a function is declared to return `void`, it should not use `return` with a value.

Take the full quiz

Browse all C quizzes