Focus
Focus
int main()
cout<<"Hello World\n";
return 0;
return 0; //statement
int main()
• Function Name
{ • Braces and Body of the
function
cout<<"Hello World\n"; • Always starts with main()
return 0;
cout<<"Hello World\n";
• You can’t change during execution of the program.
• String can be represented in TWO ways.
1. Array of characters
2. Object of a class
Dr. M. Ifjaz Ahmed, AP - II, SoC, SASTRA 7
Output using “cout”
Object of Standard
Output Stream
cout<<"Hello World\n";
Insertion / Put to
Operator
❖ In C++, data types are used to specify the type of data a variable
can hold.
❖ These are broadly classified into
1. Built-in (primitive) types,
2. Derived types, and
3. User-defined types.
Double-precision
double 8 bytes double c = 2.718;
floating-point
Single character
char 1 byte char d = 'A';
(ASCII)
Boolean type
bool 1 byte bool e = true;
(true/false)
Represents no value
void N/A void function();
(used for functions)
wchar_t Wide character type 2-4 bytes wchar_t f = L’B';
Dr. M. Ifjaz Ahmed, AP - II, SoC, SASTRA 12
Data Types in C++
2. Derived Data Types
Derived from primitive types.
int& ref = a;
Reference Alias for another variable
Int &ref = b;
A block of code with a return
Function int add(int x, int y);
type
You can use const for pointer types in different ways (const pointer, pointer to const,
etc.).
std::cout << "End of the program" << std::endl; // endl inserts newline + flushes the stream