0% found this document useful (0 votes)
18 views

Notes On C

The document discusses the basics of the C programming language including data types, operators, decision making statements and provides examples of syntax. It covers integer, floating point and character data types, arithmetic, relational and logical operators, if-else and switch statements.

Uploaded by

02. ABDUL REHMAN
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)
18 views

Notes On C

The document discusses the basics of the C programming language including data types, operators, decision making statements and provides examples of syntax. It covers integer, floating point and character data types, arithmetic, relational and logical operators, if-else and switch statements.

Uploaded by

02. ABDUL REHMAN
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/ 5

Notes on C

1. Syntax of C Program
Example

#include <stdio.h>

int main()

printf("Hello World!");

return 0;

2. Basic Data Types in C


The data type specifies the size and type of information the variable will store.

Data Type Size Description

int 2 or 4 bytes Stores whole numbers, without decimals

float 4 bytes Stores fractional numbers, containing one or more decimals. Sufficient for storing 6-7
decimal digits

double 8 bytes Stores fractional numbers, containing one or more decimals. Sufficient for storing 15
decimal digits

char 1 byte Stores a single character/letter/number, or ASCII values

3. Operators in C
C divides the operators into the following groups:

 Arithmetic operators
 Relational operators
 Logical operators
 Assignment operators
 Increment and decrement operators
 Ternary or conditional operators
Arithmetic Operators
+, -, *, /(div), % (mod)

Unary Arithmetic operators + and –

The operator which works on single operand.

Eg +2, -3.5 etc

Binary Arithmetic operators +, -, *, /, %


The operator which works on two operands.

Eg 2+3, 5-2, 3*2, 6/2, 5%2

Div(/) stores quotient and mod (%) stores remainder

5/2=2 5%2=1

Relational Operators
<, >, <=, >=,!=,==

This results in Boolean(true/false)

4<1 false 4>2 true 4<=5 true 5<=5 true 5==5 true
5!=5 false

Logical Operators
Logical operators are used to determine the logic between variables or values:

&& Logical and Returns true if both statements are true x < 5 && x < 10

|| Logical or Returns true if one of the statements is true x < 5 || x < 4

! Logical not Reverse the result, returns false if the result is true !(x < 5
&& x < 10)

Assignment Operators
=, +=, -=, *=,/=, %=
= x=5 x=5

+= x += 3 x=x+3

-= x -= 3 x=x-3

*= x *= 3 x=x*3

/= x /= 3 x=x/3

%= x %= 3 x=x%3

&= x &= 3 x=x&3

|= x |= 3 x=x|3

Increment and decrement Operators


++ Increment Increases the value of a variable by 1 ++x

-- Decrement Decreases the value of a variable by 1 --x

Ternary or conditional Operators


?:

Var=(condition)? True: False;

Max=(5>3)?5 : 3;

Ans max=5 as 5>3 is true

4. Decision Making Statements


In C, decision-making statements are technology structures enabling
programmers to make decisions based on specific conditions or criteria. In C,
there are three primary decision-making statements that you can use:
If-else statements

Switch statements

If-else statements:
The if-else statement is C's most fundamental decision-making statement. It enables us
to run one block of code if a given condition is met and another if it is not. An if-else
statement in C has the following basic syntax:

if (condition)

// code to execute if the condition is true

else

// code to execute if the condition is false

Switch statements:

The switch statement is a more complex decision-making statement that allows


you to evaluate a variable or expression against multiple possible values. The
general syntax of a switch statement in C is:

Syntax:

switch (expression)

{
case value1:

// code to execute if expression == value1

break;

case value2:

// code to execute if expression == value2

break;

...

default:

// code to execute if expression does not match any case

You might also like