+ All Categories
Home > Documents > Programming Fundamentals

Programming Fundamentals

Date post: 22-Feb-2016
Category:
Upload: olive
View: 24 times
Download: 2 times
Share this document with a friend
Description:
Programming Fundamentals. Lecture #03. #include < iostream.h > main ( ) { cout
Popular Tags:
23
Programming Fundamentals Lecture #03
Transcript
Page 1: Programming Fundamentals

Programming Fundamentals

Lecture #03

Page 2: Programming Fundamentals

#include <iostream.h>main ( ){

cout << “ Welcome to Virtual University “;

}

Page 3: Programming Fundamentals

#include:This is a pre-processor directive. It is not part of our program; it is an instruction to the compiler.It tells the C compiler to include the contents of a file

Your program will almost certainly want to send stuff to the screen and read things from the keyboard. iostream.h is the name of the file in which has code to do that work for you

A C program is made up of a large number of functions. Each of these is given a name by the programmer and they refer to each other as the program runsC regards the name "main" as a special case and will run this function first.

Page 4: Programming Fundamentals

If you forget to have a main function, or mistype the name, the compiler will give you an error.parentheses (“( )”, normal brackets) with main. Here the parentheses contain nothing. There may be something written inside the parentheses.There is a curly bracket also called braces("{ }"). For every open brace there must be a matching close. Braces allows to group together pieces of a program. The body of main is enclosed in braces.

Page 5: Programming Fundamentals

Cout known as out put stream in C and C++ Cout takes data from computer and sends it to the output.The thing between the double quotes (“ ”) is known as character string.there is a numerical address for each location of memory (block).It is difficult for us to handle these numerical addresses in our programs. So we give a name to these locations. These names are variables.

Page 6: Programming Fundamentals

Variable

X

Page 7: Programming Fundamentals

Variable

Variable starts with1. Character2. Underscore _ (Not

Recommended)

Page 8: Programming Fundamentals

Small post box

Page 9: Programming Fundamentals

Variable

Variable is the name of a location in

the memory

e.g. x= 2;

Page 10: Programming Fundamentals

Variable

In a program a variable has:1. Name2. Type3. Size4. Value

Page 11: Programming Fundamentals

=x = 2

X 2

Page 12: Programming Fundamentals

Assignment Operator

L.H.S = R.H.S.

X+ 3 = y + 4 WrongZ = x +4

x +4 = Z Wrong

Page 13: Programming Fundamentals

X = 10 ;

X = 30 ;

X

X

1030

Page 14: Programming Fundamentals

X = X + 1;X

+ 1 = 11

X

10

11

Page 15: Programming Fundamentals

Data type

int i ; -> Declaration line i

Page 16: Programming Fundamentals

#include <iostream.h>main ( ){

int x ;int y ;int z ;x = 10 ;y = 20 ;z = x + y ;cout << " x = " ;cout << x ;cout << " y = " ;cout << y ;cout << " z =x + y = " ;cout << z ;

}

Page 17: Programming Fundamentals

int x, y, z ;int x; int y; int z ;

Page 18: Programming Fundamentals

Data Types1. Int2. short3. long4. Float(real numbers or floating point)5. Double(Larg real num…twice of

Float)6. Char(x=‘a’)

Page 19: Programming Fundamentals

Arithmetic operators

Plus +Minus -Multiply *Divide/ Modulus %

Page 20: Programming Fundamentals

Arithmetic operators

i + jx * ya / ba % b

Page 21: Programming Fundamentals

% = Remainder

5 % 2 = 12 % 2 = 0

Page 22: Programming Fundamentals

4 / 2 = 25 / 2 = ?

Page 23: Programming Fundamentals

Precedence

Highest: ( )Next: * , / , %Lowest: + , -


Recommended