1 / 23

Programming Fundamentals

Programming Fundamentals. Lecture #03. #include < iostream.h > main ( ) { cout << “ Welcome to Virtual University “; }. # include:This is a pre-processor directive. It is not part of our program; it is an

olive
Download Presentation

Programming Fundamentals

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Programming Fundamentals Lecture #03

  2. #include <iostream.h> main ( ) { cout << “ Welcome to Virtual University “; }

  3. #include:This is a pre-processor directive. It is not part of our program; it is an instruction to the compiler.Ittells 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 runs C regards the name "main" as a special case and will run this function first.

  4. 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.

  5. Coutknown 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.

  6. Variable • X

  7. Variable Variable starts with • Character • Underscore _ (Not Recommended)

  8. Small post box

  9. Variable Variable is the name of a location in the memory e.g. x= 2;

  10. Variable In a program a variable has: • Name • Type • Size • Value

  11. = x = 2 X 2

  12. Assignment Operator L.H.S = R.H.S. X+ 3 = y + 4 Wrong Z = x +4 x +4 = Z Wrong

  13. 10 X = 10 ; X = 30 ; X 30 X

  14. X = X + 1; • X = 10 + 1 11 X 11

  15. Data type • inti ; -> Declaration line

  16. #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 ; }

  17. int x, y, z ; int x; int y; int z ;

  18. Data Types • Int • short • long • Float(real numbers or floating point) • Double(Larg real num…twice of Float) • Char(x=‘a’)

  19. Arithmetic operators Plus + Minus - Multiply * Divide / Modulus %

  20. Arithmetic operators i + j x * y a / b a % b

  21. % = Remainder 5 % 2 = 1 2 % 2 = 0

  22. 4 / 2 = 2 5 / 2 = ?

  23. Precedence • Highest: ( ) • Next: * , / , % • Lowest: + , -

More Related