Posts

functions and function prototyping in c++

  #include <iostream> using namespace std ; // int sum(int a, int b){ //     int c = a+b; //     return c; // } /**********FUNCTION PROTOTYPE************* */ int sum ( int a , int b ); //ab program run hojaega void greet ( void ); // void greet();---> acceptable hai //ye assurity deta hai ki sum function aage hai //int sum(int a, int b);--->acceptable //int sum(a, b);---> not acceptable //int sum(int, int);--->acceptable int main () {     //compiler main function se read krna start krta code ko.     /*************FUNCTION*************/     /*main is itself a function and yaha return zero ka mtlb hai ki     ye program successfully execute hogya ha and koi dikkat nhi aai hai*/         int k;     int s;     cout << "enter the value of k " << endl;     cin >> k;     cout << "enter the value of s " << endl; ...

structures, unions and enum in c++

  #include <iostream> using namespace std ; //structure is a user defined data type which stores value of other data types. //arrays ko use kr skte h sirf similar type ke data type ko store krne k liye typedef struct employee     {         /* data */         int employee_id; //4 bytes         char favchar; //1 byte         float salary; //4 bytes     } KS ;     union money     {         /* data */         int rice; //4         char cars; //1 //hum in teeno m se ek time pr sirf ek cheez use krenge         float homes; //4 //teeno mese koi ek set kr skte h. mtlb koi ek trh ka data type use krna chahein     };     //union memory share kradega inn teeno ke beech main     //union 4 (max) byte memory allocate krdega so that teeno ka kaam bn j...

arrays and pointers arithematic in c++

Image
  #include <iostream> using namespace std ; int main () {     /*###AN ARRAY IS A COLLECTION OF ITEMS OF SIMILAR TYPES STORES IN CONTIGUOS(CHIPAK CHIPAK KE) MEMORY LOCATION ###SOMETIMES A SIMPLE VARIABLE IS NOT ENOUGH TO HOLD ALL THE DATA ###FOR EXAMPLE hume 2500 students ke marks store krne h so 2500 variables bnana fesile nhi hoga ###to solve this problem we can define an array with size 2500 that can hold the marks of all students ###ginti 0 se start hogi ye c++ ka rule hai, 0,1,2... indices hote h*/     /********ARRAYS EXAMPLE********/     //int marks[4] = {5, 7, 57, 75}; //bracket m 4 likhna optional hai kyuki compiler khud hi figure out krelta hai     //cout<<marks[0]<<endl;     //cout<<marks[1]<<endl;     //cout<<marks[2]<<endl;     //cout<<marks[3]<<endl; //yaha humne marks naam ka ek array bnaya jo continuous data store kr raha h //another way to ma...

pointer variable and pointer to pointer variable in c++

  #include <iostream> using namespace std ; int main () {     //what is a pointer---> a data type which stores the address of other data types     //hmare device ki memory(ram) mein ek address assign kiya jata hai which is given by "&"     int a = 5 ;     int * b = & a;     // or     // int* b;     // b = &a;     cout << "the address of a is " << b << endl;     cout << "the address of a is " <<& a << endl;     //int*---> pointer (data type)     //&---> address of operator     //*---> dereference operator (value at)     cout << "the value at address of b is " <<* b << endl;     //pointer to pointer---> ek esa pointer jo pointer ke address ko store krta hai     int ** c = & b;     cout << "the address of b is " <...

break and continue in c++

  #include <iostream> using namespace std ; int main () {     for ( int i = 0 ; i < 5 ; i ++ )     {         // if (i==2){         //     break;         // }         if (i == 2 ){             continue ; //iska mtlb hai jese hi i ki value 2 hui usne kaha iss iteration(repetation)                       //ko rok do and next iteration pe jao mtlb neeche ab jo bi likha hai                       //use rok ke continue kro agli iteration pe                       //continue ke baad vala execute nahi hoga         }         cout << i << endl;         // if (i==2){         //   ...

for, while and do-while+infinite loops in c++

  #include <iostream> using namespace std ; int main () {     /*loops in c++:     there are 3 types of loops in c++:     1)For loop     2)while loop     3)Do-while loop*/         //For loop in c++:         // let me say i wanna print numbers upto 50 so i can do the following things     // #printing numbers just by cout     // cout<<1;     // cout<<2;     // cout<<3;     // and soo on       // #or     // int i=1;     // cout<<i;     // i++;     // cout<<i;     // i++;     // and soo on       // #or we can use loops for it, for very simplification     // for (int i = 0; i <= 50; i++)     // {     //     code     //     cout<<i<<endl;   ...

control structure: if else ladder and switch case

  #include <iostream> using namespace std ; int main () {     // selection control structure: if else-if... else ladder     int age;     cout << "Tell me your age" << endl;     cin >> age;     // if ((age < 18) && (age>0)) {     //     cout << "You are a child and you cannot come to my party" << endl;     // }     // else if (age == 18) {     //     cout << "You are a kid and you will get a kid pass to my party" << endl;     // }     // else if (age<1) {     //     cout<<"you are not yet born";     // }     // else if (age>100) {     //     cout<<"you are too old to come to the party";     // }     // else {     //     cout << "You are an adult and you can come to...