cpu-fundamental of c

27
Fundamental of C Programming Language

Upload: suchit-patel

Post on 16-Jan-2017

429 views

Category:

Presentations & Public Speaking


0 download

TRANSCRIPT

Page 1: Cpu-fundamental of C

Fundamental of C Programming Language

Page 2: Cpu-fundamental of C

Header Files

Header files contain set of predefined standard library functions that we can include in our C programs. But, to use these various library function, we have to include the appropriate header file:

Examples: #include<stdio.h> is a header file that

consists of standard input/output like printf(), scanf()etc.

Page 3: Cpu-fundamental of C

Character Set

Page 4: Cpu-fundamental of C

Tokens

Page 5: Cpu-fundamental of C

Keywords

C language has 32 reserved keywords.Since keywords have specific meaning, we

cannot use them as identifiers.All keywords are to be written in lower-case.

Page 6: Cpu-fundamental of C

Identifiers

They are use for naming variable,functions and arrays.

Page 7: Cpu-fundamental of C

Variables

A variable is an identifier that is used to store a data value.

It is a symbolic name assigned to the memory location where data is stored.

Example : int a = 7; 7 3 -98 Garbage value

int b = 3; a b c int c ; • A variable can have only single data item at

any given time during the program executio.

Page 8: Cpu-fundamental of C

Constants

Constants are the identifier that represent fixed values. Integer Constants: It’s an integer valued number. It consists a sequence of digits.

Page 9: Cpu-fundamental of C

Floating-point Constants: These represent numbers containing

fractional parts.• Character Constants:

It is a single character, enclosed in

apostrophes (single quotation marks). Several character constants and their ASCII values are shown below.

Page 10: Cpu-fundamental of C

The Digraph and Trigraphs

In computer programming, digraphs and trigraphs are collection of sequences of two and three characters respectively. Mostly they appear in source code, which a programming language specification requires an implementation of that language to treat as if they were one other character.

Page 11: Cpu-fundamental of C

Data Types

In C, every variable has a data type. Data type specifies the size and type of the value stored in that variable.

Page 12: Cpu-fundamental of C

Fundamental Data Type/ Primary Data Type

These data types are also called as primary or built-in or basic data types.

The modifiers signed, unsigned, long and short may be applied to character and integer basic data types. However, the modifier long may also be applied to double.

Page 13: Cpu-fundamental of C

Operators

Arithmetic Operators: These are binary operators as they take two operands. And

the operands must be numeric values. When both operands are integers, the result is integer. i.e. an

integer division result in truncation towards zero. If one is floating point and other is integer, the result is

floating point.

Page 14: Cpu-fundamental of C

Relational Operators

The associativity of these operators is left to right.

Page 15: Cpu-fundamental of C

Logical Operators

Logical operators are used to check 2 or more different conditions and take decision according to their values. Below is the list of possible conditions:

For &&

• In this case, the result is True only if both the conditions are true.

Page 16: Cpu-fundamental of C

For ||

• In this case, the result is False only if both the conditions are False.

Page 17: Cpu-fundamental of C

For !

The logical NOT operator takes single operand and reverses the value of the expresssion.

Page 18: Cpu-fundamental of C

Assignment operators

The equal to(=)is an assignment operator.

Page 19: Cpu-fundamental of C

Unary operators:

Unary operators require only one operand.there are 7 unary operators in C.

Page 20: Cpu-fundamental of C

All unary operators are used as prefix except the increment and decrement.

Page 21: Cpu-fundamental of C

Conditional Operator

This operator is used to check conditions and depending on the result, the statement is executed else we go for another execution.

Conditional operators are used in place of if-else statement.

This operator is also called as ternary operator as it takes 3 operands.

Page 22: Cpu-fundamental of C

Bitwise Operators

This is binary operator as it takes 2 operands.Both operands must be of same time.This operator is applied to each pair of bits

independent of other bits within the operand .

Page 23: Cpu-fundamental of C

For &

For |

Page 24: Cpu-fundamental of C

For ^ The XOR operator sets 1 in each bit position where its

operands have different bits and 0 where they are same.

One’s complement operator(~):It takes only one operand thus it is an unary operator.It inverts the bits of its operand i.e. each 1 is converted to 0

and vice versa.It’s used for encrypting the files.

Page 25: Cpu-fundamental of C

Shift Operators

Shift operators are used to shift the bits either to left or right.

These operators take two operands. The first operands is the bit pattern to be shifted and the second is an unsigned integer, a number that indicates the number of places the bits are shifted.

1. Left shift operator(<<):This operator shifts the bits to the left.

2. Right shift operator(>>):This operator shifts the bits to the right.

Page 26: Cpu-fundamental of C

Size of Operator

The size of operator is a special operator used to return the size of its operand in bytes.

Example:int i , j;j = sizeof(i);// It will give j=2. Since integer occupies 2

bytes and I is an integer.

Page 27: Cpu-fundamental of C

THANKS…..