C Programming Quiz: Variable Names, Output, Constants, sizeof()
12 Questions
5 Views

Choose a study mode

Play Quiz
Study Flashcards
Spaced Repetition
Chat to lesson

Podcast

Play an AI-generated podcast conversation about this lesson

Questions and Answers

What is the purpose of the & operator in C?

  • Bitwise AND
  • Address of operator (correct)
  • Pointer to operator
  • Bitwise OR
  • Which of the following is the correct way to access the fourth element of an array named nums?

  • nums.4
  • nums(4)
  • nums{4}
  • nums (correct)
  • What is the output of the following code?

    int i = 0; for (; i < 5; i++) { printf("%d ", i); }
    

  • Infinite loop
  • 1 2 3 4
  • 0 1 2 3 (correct)
  • 0 1 2 3 4
  • Which of the following statements is true about the do-while loop in C?

    <p>The loop body is executed at least once</p> Signup and view all the answers

    What is the correct way to define a function in C that returns an integer and takes two parameters a and b?

    <p>int functionName(int a, int b) { }</p> Signup and view all the answers

    Which of the following is NOT a valid way to declare a string in C?

    <p>string str = &quot;Hello&quot;;</p> Signup and view all the answers

    Which of the following is NOT a valid C variable name?

    <p>123variable</p> Signup and view all the answers

    What does the sizeof() operator return in C?

    <p>Size of the type</p> Signup and view all the answers

    What does the scanf() function do in C?

    <p>Reads formatted input</p> Signup and view all the answers

    What is the result of the expression 3 / 2 in C?

    <p>1.0</p> Signup and view all the answers

    Which of the following is a logical operator in C?

    <p>||</p> Signup and view all the answers

    What is the correct way to declare a constant in C?

    <p>const int CONSTANT = 10;</p> Signup and view all the answers

    Study Notes

    C Variable Names

    • myVariable and variable123 are valid variable names
    • 123variable is not a valid variable name (numbers cannot start a variable name)
    • _variable is a valid variable name

    C Output

    • printf("%d", x++); outputs 5 (post-increment x++ returns the original value of x)

    Declaring Constants in C

    • const int CONSTANT = 10; is the correct way to declare a constant in C

    sizeof() Operator

    • The sizeof() operator returns the size of a type or variable in bytes

    Division in C

    • The result of the expression 3 / 2 in C is 1 (integer division truncates the decimal part)

    Logical Operators in C

    • || is a logical operator in C (logical OR)

    Array Declaration in C

    • int array[10]; is the syntax to declare an array in C with 10 elements

    scanf() Function

    • The scanf() function reads formatted input from the standard input

    Terminating a C Program

    • return 0; is the correct way to terminate a C program

    Conditional Operator

    • x &gt; y ? x : y returns x if x is greater than y, and y otherwise

    Header Files in C

    • stdio.h is the header file required for input and output operations in C

    break Statement

    • The purpose of the break statement in a loop is to terminate the loop

    for Loop Syntax

    • The correct syntax for the for loop in C is for (int i = 0; i &lt; 10; i++)

    while Loop Output

    • The output of the code while (i &lt; 5) { printf("%d ", i); i += 2; } is 0 2 4

    String Declaration in C

    • char str[] = "Hello"; and char *str = "Hello"; are valid ways to declare a string in C
    • char str = "Hello"; and string str = "Hello"; are not valid ways to declare a string in C

    if Statement

    • The output of the code if (x = 6) printf("True"); else printf("False"); is True (assignment x = 6 has a non-zero value, which is considered true)

    continue Statement

    • The purpose of the continue statement in a loop is to skip the remaining code in the loop and proceed to the next iteration

    Array Access

    • arr is a pointer to the first element of the array, so printf("%d", arr); prints the memory address of the first element (garbage value)

    do-while Loop

    • The loop body of a do-while loop is executed at least once before the condition is evaluated

    Prefix Increment Operator

    • The prefix increment operator ++i increments i before returning its value, so printf("%d", ++i); outputs 11

    Array Access

    • nums[3] is the correct way to access the fourth element of an array named nums

    & Operator

    • The &amp; operator is an address of operator, which returns the memory address of a variable

    for Loop Output

    • The output of the code for (; i &lt; 5; i++) { printf("%d ", i); } is 0 1 2 3 4

    Function Definition in C

    • The correct way to define a function in C that returns an integer and takes two parameters a and b is int functionName(int a, int b) { }

    strcmp() Function

    • The strcmp() function compares two strings, returning a negative value if the first string is less than the second, zero if they are equal, and a positive value if the first string is greater than the second.

    Studying That Suits You

    Use AI to generate personalized quizzes and flashcards to suit your learning preferences.

    Quiz Team

    Description

    Test your knowledge of C programming with this quiz! Identify valid variable names, predict the output of code snippets, determine the correct way to declare constants, and understand the purpose of the sizeof() operator.

    More Like This

    Use Quizgecko on...
    Browser
    Browser