Posts

Showing posts with the label cpp

c++ string

Image
C++ string In this post, you will learn about the declaration, syntax, and how to use the string in the C++ language. The collection of the characters is called the string In the CPP, two types of string mostly used. The C-style character string. The string object in the standard library of the CPP. What is c-style string? C-style string The c-style string is the drive from the C language. Actually,CPP created after the C language is the mother language of the CPP, and a lot of the properties of the C language are found in the C++ language. The C-style string based upon the array of the characters with NULL character as a terminated character at the end of the array. The array is a one-dimensional array. How to declare C-style string? Char str[7]={'s', 't', 'r', 'i', 'n', 'g', '\0'}; In the above declaration, NULL character is in the end of the string which tells the compiler this end of the string. Other way of the declaring the

c++ Recursion

Image
C++ Recursion In this article, you will learn about the recursion in the c++ language with an explanation of the concept of the recursion. When the function calls itself within the body of the function is called the recursion in c++ language. let's see an example function(){ function();//calling itself in its body } For Example: Find the factorial of the number with the help of Recursion. #include<iostream>   using namespace std;     int main()   {   int factorial(int);   int fact,number;   cout<<"Enter the number for finding factorial: ";   cin>>number;   fact=factorial(number);        //call the recursive function  cout<<"Factorial of the number is = "<<fact<<endl;            //display the factorial return 0;   }   int factorial(int n)   {  //This is the base condition //It is very important in recursion //otherwise StackOverflow error happened   if(n>0)   return(n*factorial(n-1));    //      if number greater than zero 

c++ Data types

Image
C++ Data Types What is the data types in c++? Data types define the data of the variables in the c++ such as int(integer),char(character),float(fractional numbers),and boolean types. Data types in the c++ are divided into three groups  Built-in Derived User-defined Built-in data types C++ Int type Keyword: For  integer type   int keyword is used to declare  size: The size of the int is 4 bytes Range of the number int can store   214748647 to -2147483648 For example: int number = 410; C++ Float type For the floating type of numbers(fractional number), Keyword: float keyword  is used to declare  size: The size of the float is 4 bytes For example: float number = 410.45;  C++ Double type The double type also use for the fractional and exponential number but only different from the float type is double give more precision as compared to float data type. Keyword: Double keyword is used to declare Size: The size of the double is 8 bytes For example: double number=23.543126785 C++ char The cha

c++ storage class

C++ Storage Class In this article, you will learn the storage class in c++ and learn about the local variables, global variables, static local variables, and register variables. Every variable in the cpp has the two property  datatype  storage class The data type is int ,float and char types of data available in the cpp language. The storage class tells about the scope and lifetime of the variable or function in the CPP language. What is the storage class? The storage classes are divide into 4 major parts of the variables. local variable. global variable. static variable. Register variable C++ Local variable These variables which present under function or anywhere inside the braces ({}) are the local variable or automatic variable. Scope: The scope of the local variables only inside the brackets({}) or where variables defined in the function. If the variable declares inside the specific brackets({}) then the access the variable limited inside the brackets. If the variable declares insi

c++ pointer and function

Call by reference: using pointer In this article, you will learn about passing the pointer as an argument to the function and effectively use in the c++ program. How to use pointers as parameter in the function? First of all, learn the concept of call by reference in the c++ function article . In this method, the argument passed in the function pass by value. Actually,in the pass by value copy of the variable value created in the function that's why called pass by value. There is another to pass an argument to the function pass by reference. In this method alias of the variable is created in the function, not a copy of the variable would be created in the function. For getting knowledge about the call by reference. In the passing of pointers as argument call by reference method is used. For Example #include <iostream> using namespace std; int average(int &,int &); int main() { int a=5; int b=9; int aver; aver=average(a,b);//call the function of average cout<<av

c++ Pointers

Image
C++ Pointers In this article, we will learn about the concept of pointers in CPP and how to use pointers in our programming in CPP. What is Pointers? First of all, understand the memory address of the variable. Variable takes space from the memory of the computer. Computer memory allocates space to the variable with a memory address.  This memory address is used to find the variable in the memory. Before the pointer, we use the variable name for accessing the variable value.  But we can also use the memory address of the variable for accessing the value of the variable. In the pointers, the memory address of the variable is used to access the variables. How to access the address of the variable? Address in c++: In the CPP language, ampersand sign (&) is used to find the memory address. The ampersand sign is known as the  address of the operator . If we have the num variable, address of variable access(&num) and the value of variable access (var).For example: #include <iostre

c++ break statement

Image
c++ break statement In this article, you will learn about the break statement in the cpp language and usage of break statements in the loops. The break statement breaks the execution of the loop in which it is used. Actually, break statements also use in the switch statement to break the execution in C++ language. The basic function of the break statement to stop the execution in the program. What is the syntax of the break statement? The syntax of the break statement break; If you want to learn the usage of break statements, you must learn loops first. => While loop => do while loop => for loop How break statement work? Example break statement with for loop //understand the break statement by  //displaying the counter of loop #include<iostream> using namespace std; int main() { for(int i=0;i<5;i++) { //if loop counter reach at value of 3  //then loop terminate due to break staement  if(i==3) { break;//if a=3 then loop terminate }