Docsity

Getting Started with C, Slides of C programming

Partial preview of the text

Download Getting Started with C and more Slides C programming in PDF only on Docsity!

Getting Started

with

C

Programming Language: C

❖ High Level Programming Language

Simple

Fast

Machine Independent

Rich Library

Basic Structure of a C program

#include

int main()

return 0;

Basic Structure of a C program

#include

int main()

//Rest of you code

return 0 ;

Includes the header file that contains different standard i/o functions

Your C program starts executing from here

main() function starts with a curly brace

main() function ends with a curly brace

main() function returns an integer value (returns 0 after successful completion of the program)

printf() function

#include

int main()

printf ( “Welcome to C Programming” ) ;

return 0;

Output of the Program:

Welcome to C Programming

Tokens in C

❖ Token is

a keyword , an identifier , a constant, a string literal or Symbol.

printf (“ Welcome to C Programming ”);

How many tokens are present in this statement?

Semicolons in C

In a C program, the semicolon is a statement terminator

Each individual statement must be ended with a semicolon

#include

int main()

printf ( “Welcome to C Programming” ) ;

return 0;

End of statements

Keywords in C

32 keywords in C

A keyword can not be used as a variable name, constant name, etc

A keyword is a reserved word.

Identifiers in C

abc xyz_ _a myVariable myVariable

myIdentifier_

10abc double a 13 my Variable my%Variable my@Identifier

Some valid

identifier

Some invalid

identifier

Basic Data Types in C

Data Types

Character Integer Number Floating Point Number Boolean

short

int long int long long int

float

double long double

Data Type Size (Byte) Range

signed char 1 -128 to 127

unsigned char 1 0 to 255

float 4 1.2E-38 to 3.4E+

double 8 2.3E-308 to 1.7E+

long double 12 3.4E-4932 to 1.1E+

bool 1

Basic Data Types in C

Variables in C

A variable is a name of the memory location.

It is used to store data.

Its value can be changed, and it can be reused many times.

It is used to store data.

Syntax to declare a variable

Data_type variable_Name ;

int x ; float f1 ; double f2 ;

For exapmle:

Operators in C (Precedence and Associativity)

If more than one operators are involved in an expression, C language has a predefined rule of priority for the operators.

This rule of priority of operators is called operator precedence.

❖Precedence:

If two operators of same precedence (priority) is present in an expression, Associativity of operators indicate the order in which they execute.

❖Associativity:

Operators in C (Precedence and Associativity)

Category Operator Associativity

Postfix () [] ->. ++ - - Left to right Multiplicative * / % Left to right Additive + - Left to right Shift << >> Left to right Relational < <= > >= Left to right Equality == != Left to right Bitwise AND & Left to right Bitwise OR | Left to right Logical AND && Left to right Logical OR || Left to right Assignment = += -= *= /= %= Right to left

Precedence

High

Low