├── .vscode └── tasks.json ├── README.md ├── all.cpp ├── all.exe └── all.out /.vscode/tasks.json: -------------------------------------------------------------------------------- 1 | { 2 | "tasks": [ 3 | { 4 | "type": "cppbuild", 5 | "label": "C/C++: g++.exe build active file", 6 | "command": "C:\\MinGW\\bin\\g++.exe", 7 | "args": [ 8 | "-fdiagnostics-color=always", 9 | "-g", 10 | "${file}", 11 | "-o", 12 | "${fileDirname}\\${fileBasenameNoExtension}.exe" 13 | ], 14 | "options": { 15 | "cwd": "${fileDirname}" 16 | }, 17 | "problemMatcher": [ 18 | "$gcc" 19 | ], 20 | "group": { 21 | "kind": "build", 22 | "isDefault": true 23 | }, 24 | "detail": "Task generated by Debugger." 25 | } 26 | ], 27 | "version": "2.0.0" 28 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | **Code : all.cpp contails all basic syntaxes of C++** 2 | Join Our Discord Server - https://discord.gg/rPSK7uTe2B -------------------------------------------------------------------------------- /all.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | using namespace std; 5 | using std::cout; 6 | using std::cin ; 7 | using std::endl; 8 | 9 | int main() { 10 | /* COUT */ 11 | 12 | std::cout << "Hello Friend, This code has all the basic syntaxes of C++ " << endl; 13 | std::cout << "For any query please comntact officialwork.ashish@gmail.com " << endl; 14 | 15 | /* using (\t) chracter of adding a tap space betwwn the line */ 16 | 17 | std::cout << "The space ahead is made using (t) charachter \t used here" << endl; 18 | 19 | /* using (/) character to add / betwwen the texts */ 20 | 21 | std::cout << "addeded using the slash slash character -----> \\ ashish" << endl; 22 | 23 | /* using (\") for adding " betwwn the words */ 24 | 25 | std::cout << "ashish \" ashish \" assish" << endl; 26 | // 27 | // 28 | // 29 | // 30 | // 31 | // 32 | 33 | /* VARIABLES */ 34 | /* Syntax ---> ( variabledatatype variablename = its value ) */ 35 | 36 | int x = 10; 37 | std::cout <<"Data Type (int ) used here yo print this value " << " " << x << endl ; 38 | 39 | // assigning the value of the variable later on rather than with variable type 40 | 41 | int mysecondnumber; 42 | mysecondnumber =10; 43 | cout << "Value of the variable mysecondnumber which is assigned after declaring the varable is " << " " << mysecondnumber << endl; 44 | 45 | // we can overwrite the assigned value of our variable just by assigning a new valude to the same variable 46 | 47 | int mythirdnumber =44; // Older value of the variable (mythirdnumber) = 44 48 | mythirdnumber = 55; // new assigned value 55 which will overwrite the older value i.e, 44 49 | // here the value of my the variable (mythirdnumber) ie; 44 is overwrited by the new value 55 50 | cout << "Value of the variable mythirdnumber which is overwrited with the new assigned value is " << " " << mythirdnumber << endl; // output = 55 51 | // 52 | // 53 | // 54 | // 55 | // 56 | // 57 | // 58 | 59 | /* OPERATORS */ 60 | // ADDITION OF INTEGER DATA TYPE 61 | 62 | int a,b,c; //two variables a and b of type integer are defined here ; 63 | a=50 , b=50 ; // valued to both the integer is defined 64 | c = a+b ; 65 | cout << "Sum of the integer a and b who has value 50 each is (c = a+b) " << " " << c << endl; 66 | 67 | // we can declare many variable of single type in one line also 68 | int raabta =50 , dil= 40 , m = 66 ; // diffrent variables of same type in a single line 69 | std::cout << " Multiplication of 50*40*60 is " << " " << raabta*dil*m << endl; //multiplied the variables using * coperator 70 | 71 | //* WE CAN ASSIGH SAME VALUES TO THE DIFFRENT VARIABLE 72 | //BY SIMPLY EQUATING THEM TO EACH OTHER AND THEN DEFINING THE VALUES */ 73 | // 74 | int e,f,g; 75 | e=f=g=50; // assigned the equal values to all the variables in a single line by simple equating them ...... 76 | std::cout << " Addition of 50 +50 +50 is " << " " << e+f+g << endl; 77 | 78 | // to fix the value of any variable we use (const) object before the 79 | // variable type 80 | //ex------------------------------- 81 | const int h = 66; 82 | // from here the older value will not be overwrited because the integertype is using ----- 83 | // -------------a const object 84 | cout << " Here we have the variable names (h) whose value is fixed using the const object , the value is " << " " << h << endl; 85 | 86 | /* FOR TAKING INPUT FROM THE USER WE USE cin object .... */ 87 | int i; 88 | std::cout << " Getting input from the user using (cin) Object " << endl; 89 | cout << "Enter a Number " << endl; 90 | cin >> i ; // we never use endl with cin 91 | cout << "The Number is " << " " << i << endl; 92 | 93 | // DEFINING NUMERIC DATA TYPES 94 | // INT DOUBLE AND FLOAT 95 | int j = 1000; 96 | double k = 5.66; 97 | float l = 8.8; 98 | std::cout << "INT J DEFINED IS " << " " << j << endl; // COUT FOR INT 99 | std::cout << "DOUBLE K DEFINED HERE IS " << " " << k << endl; // COUT FOT DOUBLE 100 | std::cout << " FLOAT L DEFINED HERE IS " << " " << k << endl; // COUT FOR FLOAt 101 | //BOLLEAN DATA TYPE 102 | bool coadingisfun = true; // for true value it gives 1 as output 103 | 104 | bool fishistasty = false ; // for false it goves 0 as ouptut 105 | std::cout << "True " << coadingisfun << endl; 106 | std::cout << " False " << fishistasty << endl; 107 | 108 | 109 | //CHARACTER DATA TYPE 110 | char ashishfirstletter = a ; // this takes onl;y single character input 111 | std::cout << "Here character data type is used to print a single character ----> The character is " << " " << ashishfirstletter << endl; 112 | 113 | //STRING DATA TTYPE 114 | string name; //strind data type can take a letter as a input. 115 | name = "ashish" ; 116 | std::cout << "Here String datatype is used to print a word " << "The word is " << " " << name << endl; 117 | 118 | 119 | // STRING CONCATENATION - additing pf two string variable values 120 | string firstname = "Ashish" ; 121 | string lastname = "Singh" ; 122 | string fullname = firstname + lastname ; // here the catenation is done 123 | // but this the space will not come betwwn the ashish ans singh 124 | // the output for this full name string variable will be ashishsingh 125 | // we can fix it by adding a space character beteen the both variables ......... 126 | // 127 | string fullnamewithspace = firstname + " " + lastname ; 128 | // Now thw outtput will be ashish singh 129 | std::cout << "Simple Concatenation of two string without Space " << " (ashish + singh ) " << fullname << endl; //with out space 130 | std::cout << " Here concatenation done of two strings with a space between them " << "(ashish + singh} " << fullnamewithspace << endl; // with space 131 | // 132 | // 133 | //APPEND OPERATOR 134 | //append can also be used to concatenate two strings 135 | string firstword = "ASHISH" ; 136 | string lastword = "SINGH" ; 137 | string fullword = firstword.append(lastword); 138 | std::cout << " Here .append is used to concatenate two strings ashish.appned(singh) " << fullword << endl; 139 | 140 | // (+) op functions diffrent for int data type and string data type 141 | // for int it performs addition 142 | // for string it performs concatenation 143 | // 144 | 145 | 146 | 147 | // LENGTH OF A STRING 148 | string letter = "ashish " ; 149 | std::cout << "Checking Length of the word ashish using .length() "<< "The length is " << " " << letter.length() << endl; 150 | std::cout << "Checking length of the word (ashish) using .size() " << "The Length is " << " " << letter.size() << endl; 151 | 152 | // ACCESSING A CHARACTER IN A STRING 153 | // can be accessed by refering to the index number 154 | string aname = "cppcode"; // indexing is 0123456 155 | cout << "Accessing a character from a string word uisng its index number " << endl; 156 | std::cout << " Here we have accessed the third character of the word (cppcode) using the index number [2] " << endl; 157 | cout << "The character is -----> " << " " << aname[2] << endl; // OUTPUT = p 158 | std::cout << " Here we have accesed the first character of the word ( cppcode ) using index number [0] " < " << " " << aname[0] << endl; // O = c 160 | 161 | // a string character can also be change by referring the index nimber of the value character ..... 162 | string bname = "python " ; //indexing is 01234 163 | bname[1] = 'X' ; // index no 1 = y replaced by z 164 | cout << "Changed the character (y) of the word python uisng the index number [1] " << endl; 165 | std::cout << "Python changed to " << "Python -----> " << " " << bname << endl; //o = pzthon 166 | 167 | // string with cin 168 | string cname; 169 | cout << "Insert a word please " << endl; 170 | cin >> cname ; 171 | cout << "The Entry was " << " " << cname ; //O = INPUT BY THE USER 172 | 173 | // HERE IF THE USER INSERTS THE SENTENCE THEN THE SPACES WIIL BE CONSIDERED AS TERIMINATING CHARACTER ; 174 | // TO RESOLVE THAT WE USE getline function ........ 175 | // 176 | string dname; 177 | cout << "Insert a Sentence " << endl; 178 | getline(cin,dname); // here the spaces will not be considered as a terminating chatracter + 179 | std::cout << "The Entry was " << " " << dname << endl; 180 | 181 | // namespace cand be omitted with standard library 182 | 183 | /* OPERATORS */ 184 | 185 | // library added 186 | // #included as an header file 187 | 188 | 189 | int o , p , q ,r ; 190 | o=p=q=r=10; 191 | //ARTHEMATIC OPS 192 | // 193 | std::cout << "Addiiton (o+p+q+r) = (10+10+10+10+) " << " " << o+p+q+r << endl ; 194 | std::cout << "Substraction (o+p+q+r) = (10-10-10-10) " << " " << o-p-q-r << endl; 195 | std::cout << "Multiplication (o+p+q+r) = (10*10*10*10)" << " " << o*p*q*r << endl; 196 | std::cout << "Division (o/p) = (10/10)" << " " << o/p << "\n"; 197 | // using operators in cout , can be used also with the new int variable defined ; 198 | int nn = ++q; 199 | int mm = --q; 200 | std::cout << "Increased value of q=10 by 1 so it become q=11 using ++q" << " " << nn << endl ; // ++ increasing the value of q by 1 201 | std::cout << "Decreased value of q = 10 by 1 so it became q=9 using --q "<< " " << mm << "\n" ; // -- decresing the value of q by 1 202 | 203 | // ASSIGNMENT OPS 204 | // for assigning the values 205 | 206 | int s = 20; 207 | // = a assign op 208 | s += 5; // addition of 5 to 20 209 | cout << s << endl; 210 | int t = 20 ; 211 | t -= 5 ; // sub of 5 212 | std::cout << t << "\n"; 213 | int u = 20; 214 | u *= 5 ; //multiplucation of 5 to 20 215 | std::cout << u << endl; 216 | int v =10 ; 217 | v /= 5; // div of 5 218 | std:: cout << v << endl; 219 | // similatry mod and power assign ops are used .... 220 | // 221 | 222 | 223 | // COMPARISON OPS 224 | // return value is 0 and 1 0 for false 1 for true ..... 225 | int w = 20; 226 | int bb = 10; 227 | int asb = bb>w; 228 | int asba = bb=10; 232 | 233 | cout << asb << endl; // o = 0 234 | cout << asba << endl ; // o - = 1 235 | cout << asbb << endl ; //not equal op // o =0 236 | cout << asbc << endl ; //o =0 237 | cout << asbd << endl ; 238 | 239 | 240 | // if else statment ...... 241 | // if - runs the code if the condition is true 242 | // else - runs the block of code if the condition is false .. 243 | // else if - if is false then else if will be executed 244 | 245 | int za = 10 , zb = 30 , zc = 40 ; 246 | if ( za ==10 ) { 247 | std::cout << "Condition of IF statement was true so output is " << " " << "I LOVE INDIA" << "\n"; 248 | 249 | }; 250 | // the the if cond is true ..... 251 | 252 | // if and else 253 | // 254 | if (za==50 ){ 255 | std:: cout << "COND WAS TRUE " << endl; 256 | 257 | } else { 258 | cout << " IF Condition was false so ELSE is executed " << " " << "THE COND WAS FALSE" << endl; 259 | }; 260 | 261 | 262 | // IF ELSEIF AND ELSE 263 | if (za == 45185) { 264 | std::cout << "THE IF WAS TRUE" << endl; 265 | } else if (za==100) { 266 | std::cout << "THE FIRST ELSE IF WAS CORRECT" << endl; 267 | } else if (za> zzz ; 280 | switch (zzz) { 281 | case 1: 282 | //block of code 1 283 | std::cout << "NUMBER ENTERED IS 1 AND CASE 1 IS EXECUTED "<< endl; 284 | break; 285 | case 2: 286 | //block of code 2 287 | std::cout << "NUMBER ENTERED IS 2 AND THE CASE 2 IS EXECUTED "<< endl; 288 | break; 289 | case 3: 290 | //block of code 3 291 | std::cout << "CASE 3 NUM 3" << endl; 292 | break; 293 | case 4: 294 | //b4 295 | std::cout << "CASE 4 NUM 4"<< endl; 296 | break; 297 | case 5: 298 | //b5 299 | std::cout << "CASE 5 NUM 5"<< endl; 300 | break; 301 | case 6: 302 | //b6 303 | std::cout << "CASE 6 NUM 6" << endl; 304 | break; 305 | case 7: 306 | //b7 307 | std::cout << "CASE 7 NUM 7"<< endl; 308 | break ; 309 | case 8: 310 | //b8 311 | std::cout << "CASE 8 NUM 8"<< endl; 312 | break ; 313 | case 9: 314 | //b9 315 | std :: cout <<" CASE 9 NUM 9" << endl; 316 | break ; 317 | case 10 : 318 | //b10 319 | std::cout << "CASE 10 NUM 10"<< endl; 320 | break ; 321 | default: 322 | //bdefault 323 | std::cout << "NO CASE MATCHED "<< endl; 324 | break; 325 | }; 326 | 327 | //LOOOPS 328 | // while loop 329 | int caa ; 330 | caa =4566; 331 | while (caa==4566){ 332 | std::cout<< "THE WHILE CONDITIO WAS TRUE "<< endl; 333 | break; 334 | caa++; 335 | }; 336 | 337 | // do while looop 338 | // 339 | int cab; 340 | cab = 5644; 341 | do { 342 | cout << "THIS IS A DO SECTION OF THE LOOP"<< endl; 343 | break ; 344 | } 345 | while (cab ==4566);{ 346 | std::cout << " THIS IS THE WHILE CONDITION OF THE LOOP IT SI EXECUTED WHEN TEH WHILE LOOP CONDITION WAS TRUE"<< endl; 347 | 348 | cab++; 349 | }; 350 | 351 | // for loop; 352 | 353 | for (int i = 0; i < 5; i++) { 354 | cout<< i << endl; 355 | }; 356 | 357 | // c++ arr 358 | // 359 | string names1[10] = {"ashish " , "dipti " , "radhika" , "darsil" , "soham" , "rahul" , "vaibhav" , "aniket" , "chirag" , "aryan" }; //indexing is 012345678910 360 | //using this indexing for reffering the main values in the array main init 361 | 362 | std:: cout << names1[5] << endl; // o = rahul coz the index no is 5 to the 6th value 363 | // changeing the array element using index number 364 | names1[9] = "DESPACITO "; 365 | std::cout << names1[9] << "VALUE WAS CHANGED " << endl; 366 | 367 | 368 | // using loop with arrays 369 | // 370 | // 371 | string colors[5] = {"violet" , "blue" , "indigo" , "greem " , "yeelo"}; 372 | for (int za = 0 ; za<5 ; za++) { 373 | std::cout << colors[za] << endl; 374 | }; 375 | 376 | // getting the size of the array 377 | // 378 | int character[5] = { 5,8,5,8,4 }; 379 | int characterarraysize = sizeof(character) ; 380 | cout<< "SIZE OF THE ARRAY IS " << characterarraysize << endl; 381 | // 382 | // 383 | // 384 | 385 | 386 | // 387 | // 388 | // 389 | string names2[3][2]= { 390 | { "ashish0", "ashish1" }, 391 | { "ashish2" , "ashish3" }, 392 | { "ashish4", "ashish5" }, 393 | 394 | 395 | }; 396 | std::cout << names2[2][1] << endl; 397 | // 398 | // 399 | // 400 | //LOOP THROUGH THE MULTIDIMENSTIONAL ARRAY 401 | // 402 | // 403 | // 404 | string names3[2][3] = { 405 | { "ashish1", "ashish2" , "ashish3" }, 406 | { "ashish4" , "Ashish5", "ashish6" }, 407 | }; 408 | 409 | for (int aaaa=0;aaaa<2;aaaa++){ 410 | for (int bbbb=0; bbbb<3;bbbb++){ 411 | cout << names3[aaaa][bbbb] << endl; 412 | } 413 | }; 414 | 415 | // ashish commit checking 416 | 417 | 418 | 419 | 420 | 421 | // 422 | // 423 | // 424 | // STRUCTURES 425 | 426 | struct{ 427 | int ma1; 428 | std::string ma2; 429 | bool ma3; 430 | char ba4; 431 | }structure1; 432 | 433 | // ACCESING THE STRUCTURE VARIABLE 434 | 435 | struct { 436 | int ashishkidob; 437 | string ashishkapuranaam; 438 | 439 | 440 | 441 | }structure2; 442 | 443 | structure2.ashishkidob = 10; 444 | structure2.ashishkapuranaam = "ASHISH KUMAR SINGH "; 445 | 446 | 447 | std::cout << structure2.ashishkidob << endl; 448 | std::cout<< structure2.ashishkapuranaam << endl; 449 | 450 | // MULTIPLE STRUCTURE VARIABLES 451 | // 452 | // 453 | struct { 454 | int height; 455 | string fathersname; 456 | 457 | }ashish , dipti ; // <------ STRUCTURE VARIABLES */ 458 | 459 | ashish.height= 163; // <---- ACCESSED HEIGHT VARIABLE FOR (ashish structure ) 460 | ashish.fathersname = "RAJENDRA SINGH " ; //<----- ACCESSED FATHERSNAME VARIABLE FOR (ashish structure ) 461 | 462 | // similarly ------- 463 | dipti.height = 152; // <---- ACCESSED height variable for sricture variable named (ashish) 464 | dipti.fathersname = "SHYAMPUARI " ; //<--- ACCESSING fathersname variable for structure variable (dipti) 465 | // 466 | // 467 | // 468 | // 469 | //NAMING THE STRUCTURE 470 | // 471 | // 472 | // 473 | struct name /*<---- here we can specify the name of the structure so that we can 474 | use this structure block of code at any position the code */ { int srno; 475 | string username ; 476 | string passowrd ; 477 | 478 | }; 479 | // 480 | // 481 | // 482 | /*REFERENCES - REFERENCES ARE JUST THE NICKNAME OR ALTERNATIVE NAME FOR THE DATA VARIABLES */ 483 | // 484 | // 485 | // 486 | string ampa = "ashish"; 487 | string &b /* <----- this is the reference for the variable named (ampa) */ = ampa ; 488 | 489 | 490 | 491 | std::cout << ampa << endl; // output = ashish 492 | std::cout << &b << endl; // output = ashish // this will also have ashish as an output because &b is the reference of data varaiable ampa 493 | 494 | 495 | // 496 | // 497 | // MEMORY ADDRESS - IT IS THE ADDRESS OF THE VARIABLE WHERE THE VARIABLE IS STORED IN THE SYSTEM 498 | // WE USE $ sign BEFORE VARIABLE NAME TO GET ITS ADDRESS 499 | // 500 | string institute = "GALGOTIA UNIVERSITY "; 501 | cout << institute << endl; /* <------ HERE THE MEMORY ADDRESS WULL BE THE OUTPUT OF THE DATA VARIABLE NOT THE VALRIABLE VALUE */ 502 | 503 | // 504 | // POINTERS - these are also variables which stores the memory address of other variable as its valu e 505 | // 506 | // 507 | string varablename = "AVALUE"; 508 | string* /* <--- using (*) after data type helps to create the pointer */ pntr /* <---- this (pntr) is a pointer name which can be anything */ = &varablename ; /* memoru address of the variable names (variable name) */ 509 | std::cout << &name << endl; 510 | std::cout << pntr << endl ; /* output = memory address of the variable names (variable name) */ 511 | 512 | //DEREFERENCE - if we want to print the value of the pointer rather then the memory stored in the value of ponter 513 | //we use (* ) sign before pointername in (cout ) object 514 | // 515 | std::cout << *pntr << endl ; /* <---- THIS WILL PRINT $name as an output rather then its memory address */ 516 | 517 | 518 | 519 | return 0; 520 | } 521 | 522 | -------------------------------------------------------------------------------- /all.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mr-AshishKSingh/allcppbase/c0b001ef3a1d96f18720f1b6df2eb8dd8892e1df/all.exe -------------------------------------------------------------------------------- /all.out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mr-AshishKSingh/allcppbase/c0b001ef3a1d96f18720f1b6df2eb8dd8892e1df/all.out --------------------------------------------------------------------------------