Posts

Showing posts from May, 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