0% found this document useful (0 votes)
12 views

Lec5 Concepts of Programming

Uploaded by

tasbiha masood
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views

Lec5 Concepts of Programming

Uploaded by

tasbiha masood
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 22

CONCEPTS OF

PROGRAMMIN
G
LECTURE 05
content

 Basic structure of program


 Input/ output constructs
 Constant & variables
 Keywords & identifiers
Basic structure of
program
Basic structure of program

Documentation section

Linker section

Definition section

compulsory Global declaration

Class definition

Main function section

Sub-program section, user


define functions
Basic structure of program

documentation
linker
definition

Global declaration

Class definition

Main function
Basic structure of program
Input/ output
constructs
Input/ output constructs

 In C++ input and output are performed in the form of a sequence of


bytes or more commonly known as streams.
 Input Stream: If the direction of flow of bytes is from the device(for
example, Keyboard) to the main memory then this process is called
input.
 Output Stream: If the direction of flow of bytes is opposite, i.e. from
main memory to device( display screen ) then this process is called
output.

 That’s why we use iostream header file.


output

Standard output stream (cout):-


The data needed to be displayed on the screen is inserted in the standard output stream (cout) using
the insertion operator(<<).

//in vs code //in turbo c++

#include <iostream> #include <iostream.h>


using namespace std;
int main()
int main() {
{ cout<<“hello!";
cout<<“hello!";
getch();
return 0; return 0;
} }
Input

Standard input stream (cin):-


The data needed to be store in memory is extracted from the standard input
stream (cin) using the extraction operator(>>).
#include<iostream>
Using namespace std;
Int main(){
Int a;
Cout<<:”enter your number”<<endl;
Cin>>a;
Cout<<“your number is “<<a<<endl;
Return 0;
}
Constants &
Variable
Variable

 Variables in C++ is a name given to a memory location. It is the


basic unit of storage in a program.
 The value stored in a variable can be changed during program
execution.
 A variable is only a name given to a memory location, all the
operations done on the variable effects that memory location.
 In C++, all the variables must be declared before use.
Declaring Variable

// Declaring a single variable


type variable_name;
Int marks ;

// Declaring multiple variables:


type variable1_name, variable2_name, variable3_name
Int marks, grade , sum ;
Rules of declaring variable

 The name of the variable contains letters, digits, and underscores.


 The name of the variable is case sensitive (ex Arr and arr both are
different variables).
 The name of the variable does not contain any whitespace and special
characters (ex #,$,%,*, etc).
 All the variable names must begin with a letter of the alphabet or an
underscore(_).
 We cannot used C++ keyword(ex float,double,class)as a variable name.
Rules of declaring variable
What Are Constants

As the name suggests, a constant in C++ is a variable that cannot be


modified once it is declared in the program. We can not make any change
in the value of the constant variables after they are defined.
How To Declare Constants
Keywords &
Identifiers
Keywords

Keywords(also known as reserved words) have special meanings to the


C++ compiler and are always written or typed in short(lower) cases.
Keywords are words that the language uses for a special purpose, such
as void, int, public, etc. It can’t be used for a variable name or function
name or any other identifiers. The total count of reserved keywords is 95.
Identifiers
Identifiers are the building blocks of a program. Identifiers are
unique names that are assigned to variables, structs, functions,
class and other entities. They are used to uniquely identify the
entity within the program.
Identifiers

Main is not a keyword but pre-


define identifier. We can use it as a
variable.

You might also like