C Programming Concepts
45 Questions
0 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 maximum number of characters allowed in a variable name?

  • 64 characters
  • 8 characters
  • 16 characters
  • 30 characters (correct)
  • Which of the following is a valid variable name?

  • class mark
  • student_name (correct)
  • student-name
  • 1stVariable
  • What should a variable name not be?

  • Descriptive enough
  • A reserved word (correct)
  • Numeric in nature
  • Less than 8 characters
  • What is the correct syntax for declaring multiple integer variables in C?

    <p>int x,y,z;</p> Signup and view all the answers

    What symbol is used to assign a value to a variable in C?

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

    Which of the following types of constants is NOT recognized in C?

    <p>Symbolic constants</p> Signup and view all the answers

    In C, what type of variable retains its value even after the block in which it is declared has exited?

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

    How many types of variables are identified in C programming?

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

    Which of the following is a valid decimal constant?

    <p>-9</p> Signup and view all the answers

    What is a requirement for octal constants in C programming?

    <p>Must be prefixed with 0.</p> Signup and view all the answers

    In C programming, which of the following is NOT a valid hexadecimal constant?

    <p>0x1G</p> Signup and view all the answers

    How must hexadecimal constants be prefixed?

    <p>0x or 0X</p> Signup and view all the answers

    Which of the following represents a valid floating point constant?

    <p>1.2e3</p> Signup and view all the answers

    Which statement about integer constants in C programming is FALSE?

    <p>Decimal constants can have a leading zero.</p> Signup and view all the answers

    Identify the correct digits that can be used in octal constants.

    <p>0-7 only</p> Signup and view all the answers

    Floating point constants in C can be expressed in which of the following forms?

    <p>Fractional form.</p> Signup and view all the answers

    What is the main purpose of the increment operator?

    <p>To increment the current value of a variable by adding 1</p> Signup and view all the answers

    Which statement about the increment operator is false?

    <p>It can be used with constant values.</p> Signup and view all the answers

    In the expression 'b = ++y', what value does 'b' take if 'y' is initially 5?

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

    What does the post-increment operator do in the expression 'b = x++' when 'x' is 5?

    <p>Assigns 5 to 'b'</p> Signup and view all the answers

    Which of the following statements is true about pre-increment and post-increment operators?

    <p>Pre-increment increments the value before it's used in an expression.</p> Signup and view all the answers

    Why can't the increment operator be used on constant values?

    <p>Because constants cannot change.</p> Signup and view all the answers

    What will happen if you try to execute 'b = ++5' in code?

    <p>It will cause a compilation error.</p> Signup and view all the answers

    What is the result of the bitwise AND operation between the integers 12 and 25?

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

    What symbol denotes the increment operator?

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

    Which operator is used to perform a bitwise OR operation in C programming?

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

    What is the outcome of applying the bitwise XOR operator on 12 and 25?

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

    When the bitwise complement operator ~ is applied to the number 35, what is the expected result in terms of two's complement?

    <p>-36</p> Signup and view all the answers

    How is the 2's complement of a binary number derived?

    <p>By inverting all bits and adding 1.</p> Signup and view all the answers

    Which of the following best describes the condition for a bit to be 1 in a bitwise OR operation?

    <p>At least one bit must be 1.</p> Signup and view all the answers

    What is the correct binary representation of the number 29?

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

    In C programming, what would be the output of the statement printf("Output = %d", a | b); when a is 12 and b is 25?

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

    What is the maximum number of characters that a C identifier can have?

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

    Which of the following is NOT a valid C identifier?

    <p>1stVar</p> Signup and view all the answers

    Which of the following keywords is correctly written?

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

    What type of data does 'float' represent in C?

    <p>Floating-point number</p> Signup and view all the answers

    Which of the following is an enumeration data type in C?

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

    Which of the following data types cannot store negative values?

    <p>unsigned int</p> Signup and view all the answers

    How many bytes does the 'double' data type occupy in C?

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

    What does a variable represent in C programming?

    <p>A name for a memory location</p> Signup and view all the answers

    Which of the following represent basic data types in C?

    <p>int, float, char, double</p> Signup and view all the answers

    What is the range of a 'signed short' in C?

    <p>-128 to 127</p> Signup and view all the answers

    Which of these is counted as a derived data type?

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

    What is a characteristic of keywords in C programming?

    <p>They have fixed meanings that cannot be changed.</p> Signup and view all the answers

    What is the maximum value of an 'unsigned int' in C?

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

    Study Notes

    C Identifier Rules

    • C compiler only recognizes the first 31 characters of an identifier.
    • Identifiers can include alphabets and numbers, but must start with an alphabet.
    • Identifiers can use the underscore symbol (_) but not other special characters or spaces.
    • Identifiers cannot be reserved keywords.

    Keywords

    • Keywords are reserved words with predefined meanings.
    • Keywords cannot be used as variable names, constant names, etc.
    • All keywords are written in lowercase.
    • C has 32 keywords: auto, break, case, char, const, continue, default, do, double, enum, else, extern, float, for, goto, if, int, long, register, return, signed, short, static, sizeof, struct, switch, typedef, union, unsigned, void, volatile, while.

    Data Types

    • Data types are used to allocate memory for data and specify what type of data a variable can store.
    • Four main data types in C:
      • Basic Data Type: int, char, float, double
      • Derived Data Type: array, pointer, structure, union
      • Enumeration Data Type: enum
      • Void Data Type: void

    Basic Data Types

    • Basic data types are either integer-based or floating-point based.
    • Memory size of basic data types may vary depending on 32-bit or 64-bit operating systems.
    • Size and ranges of data types with type qualifiers:
    Type Size (bytes) Range Control String
    char or signed char 1 -128 to 127 %c
    unsigned char 1 0 to 255 %c
    int or signed int 2 -32768 to 32767 %d or %i
    unsigned int 2 0 to 65535 %u
    short int or signed short int 1 -128 to 127 %d or %i
    unsigned short int 1 0 to 255 %d or %i
    long int or signed long int 4 -2147483648 to 2147483647 %ld
    unsigned long int 4 0 to 4294967295 %lu
    float 4 3.4E-38 to 3.4E+38 %f or %g
    double 8 1.7E-308 to 1.7E+308 %lf
    long double 10 3.4E-4932 to 1.1E+4932 %Lf

    Variables

    • A variable is a name that refers to a memory location used to store data.
    • Variables are changeable and their values can be modified during program execution.

    Variable Declaration

    • Variables must be declared before they are used in a program.
    • Syntax: data_type variable-1, variable-2, ..., variable-n;
    • Separated by commas and the declaration ends with a semicolon.
    • Example: int x, y, z; float a, b; char m, n;

    Assigning Values to Variables

    • Values can be assigned to variables using the assignment operator (=).
    • Syntax: variable = constant;
    • Example: x = 100; a = 12.25; m = 'f';
    • Values can also be assigned at the time of declaration: data_type variable = constant;

    Types of Variables

    • Local Variable: Declared inside a function or block of code. Only accessible within that scope.
    • Global Variable: Declared outside of any function. Accessible from anywhere in the program.
    • Static Variable: Declared using the static keyword. Retains its value even after the function ends.

    Constants

    • Constants refer to fixed values that don't change during program execution.
    • Also called literals.
    • Types of constants in C:
      • Integer Constants:
        • decimal constant (base 10): 0, -9, 22, etc.
        • octal constant (base 8): starts with 0 (e.g., 021, 077, 033).
        • hexadecimal constant (base 16): starts with 0x (e.g., 0x7f, 0x2a, 0x521).
      • Real or Floating Point Constants: have fractional or exponential forms (e.g., -2.0, 0.0000234, -0.22E-5).
      • Character Constants: enclosed in single quotes (e.g., 'a', 'b', 'c').
      • String Constants: enclosed in double quotes (e.g., "hello", "world").
      • Backslash Character Constants: special characters represented with a backslash (e.g., '\n' for newline).

    Increment Operators

    • Increment operators increase the value of a variable by 1.
    • Two types:
      • Pre-Increment: Increments the variable's value before using it in the expression (++y).
      • Post-Increment: Increments the variable's value after using it in the expression (x++).

    Bitwise Operators

    • Work on individual bits of data.
    • Types:
      • Bitwise AND (&): Results in 1 if both corresponding bits are 1.
      • Bitwise OR (|): Results in 1 if at least one corresponding bit is 1.
      • Bitwise XOR (^): Results in 1 if corresponding bits are different.
      • Bitwise Complement (~): Inverts each bit (0 to 1, 1 to 0).

    2's Complement

    • A method used to represent negative numbers in binary.
    • The 2's complement of a number is equal to its complement (inverting all bits) plus 1.

    Studying That Suits You

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

    Quiz Team

    Related Documents

    Description

    Test your knowledge of C programming rules including identifier naming conventions, keyword usage, and data types. This quiz covers the essentials you need to understand to write valid C code effectively.

    More Like This

    Use Quizgecko on...
    Browser
    Browser