0% found this document useful (0 votes)
7 views9 pages

Chapter 3 Notes

The document provides an overview of input and output functions in C, including examples of printf() and scanf(). It details various operators, their types, and functions, including arithmetic, relational, and logical operators, as well as the use of assignment and increment/decrement operators. Additionally, it covers floating-point data types, format specifiers, escape sequences, and the functionality of different operators in C.

Uploaded by

aayanfarhan99
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views9 pages

Chapter 3 Notes

The document provides an overview of input and output functions in C, including examples of printf() and scanf(). It details various operators, their types, and functions, including arithmetic, relational, and logical operators, as well as the use of assignment and increment/decrement operators. Additionally, it covers floating-point data types, format specifiers, escape sequences, and the functionality of different operators in C.

Uploaded by

aayanfarhan99
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

1.

Input Functions and Output Functions in C


Input Functions: Functions that take input from the user or another source. Example: scanf(),
getchar(), gets().
Output Functions: Functions that display output on the screen. Example: printf(), putchar(), puts().

2. printf() and scanf() in C


• printf(): Used to display output on the screen.
Example:

• printf("Hello, World!");

Output:

Hello, World!

• scanf(): Used to take input from the user.


Example:

• int age;

• printf("Enter your age: ");

• scanf("%d", &age);

• printf("Your age is %d", age);

Input: 25
Output: Your age is 25

3. Statement Terminator in C
In C, a statement is terminated using a semicolon (;).
Example:

int a = 5;

printf("%d", a);

Each statement ends with ;, which tells the compiler that the statement is complete.

4. Operators in C and Their Types


Operators are symbols used to perform operations on variables and values.

Types of Operators in C:

1. Arithmetic Operators (+, -, *, /, %)

2. Relational Operators (==, !=, <, >, <=, >=)


3. Logical Operators (&&, ||, !)

4. Bitwise Operators (&, |, ^, ~, <<, >>)

5. Assignment Operators (=, +=, -=, *=, /=, %=)

6. Increment & Decrement Operators (++, --)

7. Conditional (Ternary) Operator (? :)

8. Comma Operator (,)

9. Sizeof Operator (sizeof)

10. Typecast Operator ((type))

5. Arithmetic Operators in C
Used for mathematical calculations.

Types:

1. Addition (+): a + b

2. Subtraction (-): a - b

3. Multiplication (*): a * b

4. Division (/): a / b

5. Modulus (%): a % b (gives remainder)

Example:

int a = 10, b = 3;

printf("%d", a % b); // Output: 1

6. Increment and Decrement Operators in C


• Increment (++): Increases value by 1

• Decrement (--): Decreases value by 1

Types:

1. Pre-increment (++a): Increases value first, then uses it.

2. Post-increment (a++): Uses value first, then increases it.

3. Pre-decrement (--a): Decreases value first, then uses it.

4. Post-decrement (a--): Uses value first, then decreases it.

Example:
int a = 5;

printf("%d", ++a); // Output: 6

7. Assignment Operator vs. Equal to Operator


Operator Symbol Purpose Example

Assignment = Assigns value to a variable a = 5;

Equal to == Compares two values if(a == 5)

Example:

int a = 10; // Assignment

if(a == 10) // Comparison

printf("a is 10");

8. Floating-Point Data Type in C


Floating-point numbers store decimal values.

Uses:

• Used for mathematical calculations involving fractions.

• Example: Price, temperature, scientific calculations.

Example:

float pi = 3.14;

printf("%f", pi); // Output: 3.140000

9. Format Specifiers in C
Format specifiers define the type of data in printf() and scanf().

Data Type Format Specifier Example

Integer %d or %i printf("%d", 5);

Float %f printf("%f", 3.14);

Character %c printf("%c", 'A');

String %s printf("%s", "Hello");


Data Type Format Specifier Example

Double %lf printf("%lf", 3.141592);

10. Escape Sequences in C


Escape sequences are special characters preceded by \.

Escape Sequence Meaning

\n New Line

\t Tab Space

\\ Backslash

\" Double Quote

\' Single Quote

Example:

printf("Hello\nWorld");

Output:

Hello

World

11. Function of All Operators in C


Arithmetic Operators (+, -, *, /, %)

Perform mathematical operations.

Relational Operators (==, !=, <, >, <=, >=)

Compare values.

Logical Operators (&&, ||, !)

Perform logical operations (AND, OR, NOT).

Bitwise Operators (&, |, ^, ~, <<, >>)

Operate at the binary level.

Assignment Operators (=, +=, -=, *=, /=, %=)

Assign values to variables.

Increment & Decrement (++, --)


Increase or decrease values.

Conditional Operator (? :)

Shorter way of writing an if-else statement.

Comma Operator (,)

Used to separate expressions.

Sizeof Operator (sizeof)

Finds the memory size of data types.

Typecast Operator ((type))

Converts one data type to another.

You might also like