quiz image

Operators in C Language Quiz

SprightlyVision avatar
SprightlyVision
·
·
Download

Start Quiz

Study Flashcards

10 Questions

What does the putchar function in C do?

Writes output to the screen

Which function is used to read a single string from the keyboard in C?

gets

What is the purpose of the scanf function in C?

Reads input from the standard input stream according to the format provided

Which format specifier would you use for reading a character in C?

%c

What does the sprintf function in C stand for?

String print

How is printf() different from puts() in C?

puts() displays a value on the console screen, while printf() formats and writes output.

Which function is used to display a value like float, integer, character, or string on the console screen in C?

printf

'&' operator is used in which function for storing variable values at memory locations?

scanf

'gets' and 'puts' functions are primarily used for what in C?

'gets' reads a value from the keyboard and 'puts' writes output on screen

What type of value does %f represent as a format specifier in C?

Float

Study Notes

Operators in C

  • Operators are symbols used to perform operations
  • There are several types of operators in C:
    • Arithmetic operators
    • Relational operators
    • Shift operators
    • Logical operators
    • Bitwise operators
    • Turnery or Conditional operators
    • Assignment operators
    • Misc. operators

Precedence of Operators

  • Precedence specifies the order in which operators are evaluated
  • Associativity specifies the direction of evaluation (left to right or right to left)

Arithmetic Operators

  • Used for performing mathematical operations
  • Examples:
    • Plus operator (+)
    • Minus operator (-)
    • Multiplication operator (*)
    • Division operator (/)
    • Modulus operator (%)

Relational Operators

  • Used for comparing values
  • Examples:
    • Less than (<)
    • Greater than (>)
    • Less than or equal to (<=)
    • Greater than or equal to (>=)
    • Equal to (==)
    • Not equal to (!=)

Logical Operators

  • Used for combining conditions
  • Examples:
    • Logical AND (&&)
    • Logical OR (||)
    • Logical NOT (!)

Bitwise Operators

  • Used for manipulating bits
  • Examples:
    • Bitwise AND (&)
    • Bitwise OR (|)
    • Bitwise XOR (^)
    • Bitwise NOT (~)
    • Right shift (>>)
    • Left shift (<<)

Assignment Operators

  • Used for assigning values
  • Examples:
    • Simple assignment (=)
    • Plus and assignment (+=)
    • Subtract and assignment (-=)
    • Multiply and assignment (*=)
    • Divide and assignment (/=)
    • Modulus and assignment (%=)

Increment and Decrement Operators

  • Used for incrementing or decrementing values
  • Examples:
    • Pre-increment (++)
    • Post-increment (++)
    • Pre-decrement (--)
    • Post-decrement (--)

Conditional Operator

  • Used for conditional statements
  • Syntax: exp1 ? exp2 : exp3

Bitwise Operators with Examples

  • Bitwise AND operator (&)
  • Bitwise OR operator (|)
  • Bitwise XOR operator (^)
  • Right shift operator (>>)
  • Left shift operator (<<)

Special Operators

  • Comma operator (,)
  • Sizeof operator (sizeof)
  • Pointer operators (& and *)
  • Member selection operators (.)

Evaluating Arithmetic Expressions

  • Evaluate expressions using operator precedence and associativity rules

  • Follow the steps:

    1. Determine the order of operator binding
    2. Obtain the equivalent mathematical equation
    3. Evaluate the expression by following the operator binding sequence### Operator Binding in Arithmetic Expressions
  • The steps to determine operator binding in an arithmetic expression involve:

    • Evaluating unary operators (unary +, unary -, ++, --) with right-to-left associativity
    • Evaluating multiplicative operators (*, /, %) with left-to-right associativity
    • Evaluating additive operators (+, -) with left-to-right associativity

Evaluating an Arithmetic Expression

  • The expression -a + b * c - d / e + f is evaluated by following the operator binding sequence
    • Unary operators are bound to their operands from right to left
    • Multiplicative operators are bound to their operands from left to right
    • Additive operators are bound to their operands from left to right
  • The final expression is evaluated by following the operator binding sequence

Input-Output Operations

  • Input refers to providing data to a program
  • Output refers to writing data to a file or displaying it on the screen
  • Reading and writing characters can be done using printf() and scanf() functions
    • getchar() function reads a single character from the keyboard and stores it in a character variable
    • putchar() function displays a character value on the screen
  • gets() function reads a single string from the keyboard and stores it in a character array
  • puts() function displays a string on the screen

Formatted Input and Output

  • Formatted I/O functions are used to take various inputs from the user and display multiple outputs
  • These functions use format specifiers to display output in different formats
  • Format specifiers include %d for signed integer, %c for character, %f for decimal floating-point, %s for string, and more
  • printf() function is used to display output on the console screen
  • scanf() function is used to take input from the keyboard
  • sprintf() function stands for "string print" and is used to store formatted strings
  • sscanf() function is used to read formatted input from a string

Test your knowledge on various types of operators in the C language, including arithmetic, relational, logical, bitwise, conditional, and more. Learn about the precedence of operators and how they are used in programming.

Make Your Own Quizzes and Flashcards

Convert your notes into interactive study material.

Get started for free

More Quizzes Like This

C Language Operators Quiz
80 questions
C Language Operators Quiz
10 questions
Operators in C Language
40 questions
Use Quizgecko on...
Browser
Browser