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

Hello World? What Do You Even Mean!?: #Include

This document provides explanations of key concepts in C++ including: 1. The main function is called when the program runs and contains the code to be executed. It prints "Hello world!" to standard output. 2. Comments and directives like #include tell the compiler how to process and interpret code. 3. Namespaces like std contain standard library elements that can be inserted into code using declarations like using namespace std. 4. Other concepts explained include preprocessors, compilers, loops, decision making using if/else and switch statements, functions, arrays, conditional operators, classes and objects, inheritance, and multiple inheritances. Tables and class diagrams are provided as references.

Uploaded by

Lipika Kanojia
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
52 views

Hello World? What Do You Even Mean!?: #Include

This document provides explanations of key concepts in C++ including: 1. The main function is called when the program runs and contains the code to be executed. It prints "Hello world!" to standard output. 2. Comments and directives like #include tell the compiler how to process and interpret code. 3. Namespaces like std contain standard library elements that can be inserted into code using declarations like using namespace std. 4. Other concepts explained include preprocessors, compilers, loops, decision making using if/else and switch statements, functions, arrays, conditional operators, classes and objects, inheritance, and multiple inheritances. Tables and class diagrams are provided as references.

Uploaded by

Lipika Kanojia
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Hello World? What do you even mean!?

#include <iostream> // Lines beginning with a hash sign (#) are directives read and interpreted by
what is known as the preprocessor.

using namespace std; //standard

int main() //The function named main is a special function; it is the function called when
the program is run. The execution of all programs begins with the main function.

{
A sentence within quotes
cout << "Hello world!" << endl; //cout-> Character output ("Hello world!"), is the
content inserted into the
//<< insertion operator standard output(your
computer screen).
return 0;
Note!
} The statement ends with
a ; and this symbol
marks the end of a
statement.

IMPORTANT: cout is part of the standard library, and all the elements in the standard C++ library are
declared within a namespace called std. The most typical way to insert components in the standard
output(your computer screen) is by means of using declarations:

using namespace std;

What in gods name is a preprocessor?!

In simple words, it tells the compiler to process this statement first or it means that it
gives the statement a high priority.

What did you just say, compiler, eh?


Yeah! It is just another program that changes whatever you write on the computer to
what a normal computer could understand. It is like a translator between computer and
petty humans.
Looooops!
What do you understand by the term Loop? Exactly! Over and over and over again!

There are 3(okay, 5) ways decision making is represented in c++

1. If statement
2. If..else statement
3. Switch statement
4. Nested if statement
5. Nested switch statement Examples done in
There are 3(okay, 4) ways a loop can be represented in c++ class, pay attention!
1. For
2. While
3. Do..while
4. Nested loop

Conditional operator

Exp1 ? Exp2 : Exp3;

The value of a ? expression is determined like this: Exp1 is evaluated. If it is true, then Exp2 is
evaluated and becomes the value of the entire ? expression. If Exp1 is false, then Exp3 is evaluated
and its value becomes the value of the expression.

The ? is called a ternary operator because it requires three operands and can be used to replace if-
else statements, which have the following form:

if(condition){
var = X;
}else{
var = Y;
}
Functions

The general syntax for a function in c++ is:

return_type function_name( parameters ) {


body of the function
}

Arrays

It is a collection of same type of variables.

return_type arrayName [ arraySize ];

array initialization is done as follows:

int room_no[] = {15, 25, 33, 16, 94, 78};

or

int room_no[6] = {15, 25, 33, 16, 94, 78};

accessing the array number 3

cout<<room_no[3];

How to pass an array in a function

int getSum(int A[], int size);

Classes and objects(constructor destructor as well)


Look at examples in the tutorial. [Learn more about set and get function at home as well]

Inheritance of a class

class derived-class: access-specifier base-class

Multiple inheritances

class derived-class: access baseA, access baseB....


Important tables that you may need
Please note: Tables referred from
Tutorialspoint.

IMPORTANT: class diagrams, very good explaination @


https://cppcodetips.wordpress.com/2013/12/23/uml-class-diagram-explained-with-c-
samples/ (read this through and mark what you do not understand)

You might also like