//the statement that jab class likhte h to bilkul bi memory nhi khai jati and //objects bnane pe hi memory allocate hoti hai is not completlety true (partially true) /*jab hum class bnate hai to kuch memory (for example functions ki) sare functions ke liye same allocate ki jati hai otherwise har object ke liye alg memory allot hogi*/ #include <iostream> using namespace std ; class shop { int itemId [ 100 ]; int itemPrice [ 100 ]; int counter; public: void initCounter ( void ) { counter = 0 ; } void setPrice ( void ); void displayPrice ( void ); }; void shop :: setPrice ( void ){ cout << "enter id of your item no" << counter + 1 << endl; cin >> itemId [counter]; cout << "enter price of your item" << endl; cin >> itemPrice [counter]; counter ++ ; } void ...
#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...
#include <iostream> using namespace std ; // int product(int a, int b) // { // int c = a*b; // return c; // } /***********INLINE FUNCTION********* */ /*C++ provides inline functions to reduce the function call overhead. An inline function is a function that is expanded in line when it is called. When the inline function is called whole code of the inline function gets inserted or substituted at the point of the inline function call. This substitution is performed by the C++ compiler at compile time. An inline function may increase efficiency if it is small.*/ //bade functions m inline function use nhi krna as vo pura replace hojaega //call ki jagah so zyada memory khaega //incline function ek request hoti hai to the compiler, compiler decide krta hai vo requst accept krni ya nahi inline int product ( int a , int b ) { int c = a * b; //use of static variables is n...
Comments
Post a Comment