Posts

Showing posts from 2020

Function in C++ with example & declaration, initialization function in c++

Image
                      Function in C++ A function is a group of statements that together perform a task. Every C++ program has at least one function, which is  main() , and all the most trivial programs can define additional functions. You can divide up your code into separate functions. How you divide up your code among different functions is up to you, but logically the division usually is such that each function performs a specific task. A function  declaration  tells the compiler about a function's name, return type, and parameters. A function  definition  provides the actual body of the function. The C++ standard library provides numerous built-in functions that your program can call. For example, function  strcat()  to concatenate two strings, function  memcpy()  to copy one memory location to another location and many more functions. A function is known with various na...

Array in c++ programming

Image
Array " Array is a Set of similar datatype variable under a single name." To declare an array syntax:-        Datatype arrayname[ size ]; To initialization an array int a[5]={78,45,12,89,56}; Array initialization Important points about array The address of first element is called base address ab array. Array name represent base address of an array .       Ex-48252 This is a unique no used to access an element in an array is know as base address of array. The index of first element is always zero (0) an array. The index of last element is always one less of array size. Size of array= 5. Last index of array=5-1=4. The positive of element in a array always once more it's index. Index of 45=1. Position of 45=2. Access an element set value. get value. set value syntax       int a[2]={10,20}; get value   syntax           int a[2]; ...

Loops in c++ programming

Image
Loop Loop A close patt is called loop. There are three type of loop:- For loop. While loop. Do while loop. 1. For loop To run the body continuously until a required condition is fullfill is called looping.  It is used to perform looping Operation. When the condition will become false the execution for loop will be stopped. Syntax For loop Syntax Example #include<stdio.h> int main () { for ( int i =1 ;i <=10 ;i ++ ) { cout << i << " \n " ; } } ### Output ### 1 2 3 4 5 6 7 8 9 10 2. While loop To run the body continuously until a required condition is fullfill is called looping.  It is used to perform looping Operation. When the condition will become false the execution for loop will be stopped. Syntax While loop syntax #include<iostream.h> int main () { int i =1 ; while (i <=10 ) { cout << i << " \n " ; i ++ ; } } ### Output ### 1 2...

Switch case statement

Image
Switch case Switch case statement allow us to execute one statement from many statement are that statement is called case. Actually in which statement, inside the body of switch a number of case are used and a perameter are passed and from which case this parameter is matched, execute. Syntax In the statement a value/number is passed in the place of parameter and that case will execute which is equal to that value/ number. If no case matched with parameter then default case will execute. Example #include<stdio.h> int main () { //Assigning parameter's value int p =2 ; switch (p) { case 1 : cout<< "it is case 1" ; break ; case 2 : cout<< "it is case 2" ; break ; case 3 : cout<< "it is case 3" ; break ; default: cout<< "no case matched" ; } return 0 ; } ### output ### it is case 2 //because p=2 so case 2 will execute

If-else statement in c++

Image
If statement syntax    If the condition is true it's body execute otherwise dose not execute. In the case of if in the place of condition always zero and non zero condition is cheked in which zero means condition is false and non zero means condition is true. Example #include<iostream.h> #include<conio.h> int main () { //Assigning value to the variable int x =50 ,y =20 ; //checking the condition if (x > y) { cout<< "x is greater than y" ; } } ### Output ### x is greater than y If-else statement:- syntax Example #include<iostream.h> int main () { //Assigning value to the variable int x =50 ,y =20 ; //checking the condition if (x == y) { cout<< "x is equal to y" ; } else { cout<< "x is not equal to y" ; } } ### Output ### //In the above program condition is false because the value of x=50 and the value of y=20 and they are not equal so else part will execute. x is not eq...

Operators of c++

Image
Operator It is a special symbol which is used to perform logical or mathematical operation on data or variable. Operand It is a data or variable on which the operation is to be performed. Types of Operator ⇒Arithmetic Operators ⇒Relational Operators ⇒Logical Operators ⇒Assignment Operators ⇒Bitwise Operators ⇒Increment/Decrement Operators ⇒Conditional Operators ⇒Special Operator Arithmetic Operators Symbol Operation Example + Addition x+y - Subtraction x-y * Multiplication x*y / Division x/y % Modulus x%y #include<iostream> using namespace std; int main () { int a =5 ,b =3 ; cout << (a + b) << " \n " ; cout << (a - b) << " \n " ; cout << (a * b) << " \n " ; cout << (a / b) << " \n " ; cout << (a % b) << " \n " ; //%(modulus) holds remainder } /* ### Output ### 8 2 15 1 2 */ Relational operator Symbol ...

Storage class in c++

Image
Storage class A storage classes in c++ defines the  scope,liftime,default initial value  and  storage space  of a variable. There are four storage classes in c++ 1.automatic. 2.static. 3.register. 4.external.                 Automatic: storage class 1.Automatic variables are declared inside a function in which they have to used. 2.When the function is called automatic variables are created and destroyed when function is exited. 3.Automatic variables can not be used outside that function in which it is declared it means we can say that it is private member. 4.Automatic variables are also known as local variable. 5. auto  keyword is used to declare automatic type variable. Features of automatic variable Storage Memory Default Initial Value Garbage Value(Unpredictable value) Life Till the control remains within the function in which it is defined Scope Local to the function in which auto v...