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

PPC Notes

For Sem 1

Uploaded by

bollysony152
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)
8 views9 pages

PPC Notes

For Sem 1

Uploaded by

bollysony152
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

CProgramming Language

History of C
Cwas developed by Dennis Ritchie in 1972 at Bell Laboratories of AT&T. It is the
successor to the language B and was built to construct the utilities of Unix.

Features of C Language
Cis a simple, fast, and efficient language that is hardware independent
and general-purpose.

Portability: C is hardware independent, meaning that programs written in C can


run on any machine with a C compiler.
General-purpose:C can be combined with other languages to build
applications.
" Modularity: Blocks of code can be called from other parts.
" Procedural: A set of predefined instructions are carried out step by step.
Extensibility: If code is already written, you can add new features with a few
alterations.
" High-level language: C is very close to human language.

Applications of C Language
" Android OS, Linux kernel, Unix kernel are built using C.
Creating web brovwsers like Google Chrome.
Developing databases like MySQL.
Scripting programs and drivers of embedded systems.
Building applications like Adobe Photoshop.
" Development of video games.
Structure of C Language

Preprocessor Statements
Preprocessor statements are used to include header files.
" #include<stdio. h>; includes the standard input/output header file.

Global Declaration
Global declarations provide information about variables.

" int numl=10;: declares an integer variable numl with a value of 10.

Main Function Prototype


The main function is the entry point of a C program.
" void main(): does not return a value.
" int main ():returns a value.

Statements and Expressions


Statements and expressions are enclosed in ().

printf(): a libraryfunction to display output.


scanf(): used to take input from the user.
Data Types and Sizes
Data Type Size

int 2 bytes
char 1byte

sizeof Function
The sizeof () function is used to find the exact memory space allocated
for each data type.
#include<stdio. h>
#include<conio . h>
void main ()
clrscr0:
printf ("\n Storage size of integer is %d", sizeo f(int) ) ;
printf("\n Storage size of char is %d", sizeof (char) );
getch();

Constants and Variables

Constant Variables
The value of constant variables remains the same once assigned.

const float pi=3.142;:declares a constant float variable pi with a value of


3.142.

Type Casting
Type casting is changing a variable from one data type to another.
Implicit conversion: the compiler automatically converts one data type to
another.
Explicit conversion: the user performs the conversion using the following
syntax: (data type) expression;

#include <stdio.h>
int main ( )

int x=65;
printf("%C", x) ;
return 0;
}

Operators
Arithmetic Operators
Arithmetic operators are used to perform mathematical operations.

+, -

#include <stdio . h>


#include<conio.h>
int main ( )

int numl, num2, result;


clrscr(0:
printf ("Enter 2 numbers");
Scanf("%d%d",&numl,&num2);
result=numl+num2 ;
printf ("\n Addition value is %d", result);
result=numl-num2;
printf("\n Subt raction value is %d", result) ;
result=num1*num2;
printf("\n Multiplication value is %d", result) ;
getch(0;
return 0;

Assignment Operators
Assignment operators are used to assign values to variables.
#include <stdio. h>
#include<conio .h>
void main()
int num2;
clrscr):
printf("0riginal value is %d", num);
num+=2;
printf("Current value is %d", num) ;
num-=2;
printf("Current value is %d", num);
num*=2;
printf ("Current value is %d", num);
getch( );
)

Relational Operators
Relational operators are used to find the relation between two variables.

#include <stdio . h>


#include<conio . h>
void main ()

int numl=]0, num2=20;


clrscr0;
printf ("is num 1 greater? %d", (numl>num2) );
printf ("is num 2 greater or equal? %d", (num2>=numl) );
printf ("is numl & num2 not equal? %d", (numl !=num2));
getch();

Logical Operators
Logical operators are used to perform logical operations.
#include <stdio . h>
#include<conio. h>
void main ()

int numl=l0, num2=20, num3=30, result;


clrscr0:
printf ("3 numbers are %d%d%d", numl, num2, num3 );
result= (numl>num2 ) && (numl>num3) ;:
printf ("Is num 1 greatest? %d" result);
m2>num3 );
res

(num2>num1)TIr
intf("IS num 2 gr than numl or num3? %d", result) ;
result=(num3>num2 )&&(num3>numl) ;
printf ("Is num 3 thegreatest number? %d", result) ;
getch() ;

Conditional or Ternary Operators


Conditional or ternary operators return one value if the condition is true
and another value if the condition is false.

" Syntax: (Condition ?t ruevalue : falsevalue) ;

#include <stdio . h>


#include<conio.h>
void main( )
{
int numl=20, num2=10, result;
clrscr(0;
printf ("Numbers are %d %d", numl, num2) :
result= (numl>num2 ? numl: num2);
printf("Greater value is %d", result) ;
getch( );

Variable Declaration and Initialization

Variable Declaration
Variables are capable of storing temporary data within a program.
" int age;: declares an integer variable age.
" float salary;:declares a float variable salary.

Variable Initialization

Initialization is assigning a value to a variable using the -sign.


int numl=5, num2=7;:declares and initializes two integer variables numl and
num2,

Block Structure

Block Structure

A block structure is a way to group related data together into a single


unit.

#include<stdio.h>
lude<conio . h>
#inc
void main ()
int num=l;
clrscr(0:
if (num>0)

printf("%d",num);
}
getch();
)

Post and Pre Increment/Decrement Operators


Post Increment/Decrement Operators
Post increment/decrement operators increase/decrease the value by 1
after the value is assigned.

" variable++: post increment operator.


" variable- -: post decrement operator.
Pre Increment/Decrement Operators
Pre increment/decrement operators increase/decrease the value by 1
before the value is assigned.
++variable: pre increment operator.
- variable: pre decrement operator.

#include<s tdio.h>
#include<conio.h>
void main ( )

int age=25, num=30;


clrscr 0:;
printf("POST INCREMENT %d", age++);
printf("PRE INCREMENT %d", ++age);
printf ("POST DECREMENT %d",num- -);
printf("PRE DECREMENT %d", -- num);
getch();

Macros

Macros
A macro is a piece of code in a program that is replaced by the value of
the macro.

" #define PI 3. 142: defines a macro PI with a value of 3.142.

#include<stdio.h>
#include<conio .h>
int main()

clrscr();
printf("The value of PI is %f", PI);
getch():
return 0;
Flow Chart Symbols

Flow Chart Symbols


Flow chart symbols are used to represent the flow of information and
processing in a program.
" Terminal: The oval symbol indicates Start, Stop, and Halt in a program's logic
flow.
" Input/Output: A parallelogram denotes any function of input/output type.
" Decision Diamond: The diamond symbol represents a decision point.
" FlowLines: Flow lines indicate the exact sequence in which instructions are
executed.

Operator Precedence

Operator Precedence
Operator precedence determines which operation is performed first in an
expression with more than one operator with different precedence.

" Higher precedence operators:, /


" Lower precedence operators: +,

You might also like