Posts

Showing posts from April, 2025

Reference Variables & Typecasting in C++

  #include <iostream> using namespace std ; int c = 45 ; //Global Variable int main () {     // ****************Built in data types******************     // int a,b,c;     // cout<<"Enter the value of a : "<<endl;     // cin>>a;     // cout<<"Enter the value of b : "<<endl;     // cin>>b;     // c = a+b;     // cout<<"The sum is : "<<c<<endl;     // cout<<"The global c is : "<<::c;    //Global Variable     // *****************float,double and long double literals*****************     // float d=34.4;     // long double e = 34.4;     //By default, "34.4" will be considered as double, not float     //But "34.4f" will be considered as float     //"34.4l" will be considered as long double     // cout<<"The size of 34.4 is "<<size...

Header files & Operators in C++

  // There are two types of header files: // 1. System header file: It comes with the compiler #include <iostream> // 2. User defined header file: It is written by the programmer // #include"this.h"    This will produce an error if this.h is not present in the current directory using namespace std ; int main () {     int a = 4 , b = 5 ;     cout << "Operators in C++ : " << endl ;     cout << "Following are the types of operators in C++" << endl ;     //Arithmetic Operators     cout << "The value of a + b is : " << a + b << endl ;     cout << "The value of a - b is : " << a - b << endl ;     cout << "The value of a * b is : " << a * b << endl ;     cout << "The value of a / b is : " << a / b << endl ;     cout << "The value of a % b is : " << a % b << endl ; ...

Basic Input/Output & More in C++

Image
  #include <iostream> using namespace std ; int main () {     int num1 , num2 ;     cout << "Enter the value of num1 : \n " ;     cin >> num1 ;     cout << "Enter the value of num2 : \n " ;     cin >> num2 ;     cout << "The sum is : " << num1 + num2 ;     // '<<' is called Insertion operator     // '>>' is called Extraction operator     return 0 ; } OUTPUT: PS D:\C++> > cd "d:\C++\" ; if ($?) { g++ tut5.cpp -o tut5 } ; if ($?) { .\tut5 } Enter the value of num1 : 3 Enter the value of num2 : 8 The sum is : 11 PS D:\C++>

Variable Scope & Data Types in C++

Image
  #include <iostream> using namespace std ; int glo = 6 ;    //Global Variable void sum () {     int a ;     cout << glo ; } int main () {     //We can make same name local and global variable but precedence will get local variable     //local variable will get more importance as compare to global variable     int glo = 9 ;  //Local Variable     glo = 78 ;     // int a = 4;     // int b = 5;     int a = 14 , b = 15 ;     float pi = 3.14 ;     char c = 'u' ;     bool is_true = true ;     bool is_false = false ;     sum ();     cout << glo << is_true << is_false ;     // cout<<"This is tutorial four.\nHere the value of a is "<<a<<"\nThe value of b is "<<b<<"\n";     // cout<<"The value of pi is : "<<pi; ...

Variables & Comments in C++

Image
  #include <iostream> using namespace std ; // This program is about Variables and Comments in C++ /*This is a multiline comment*/ int main () {     int sum = 6 ;     cout << "Hello World" << sum ;     return 0 ; } OUTPUT: PS D:\C++> cd "d:\C++\" ; if ($?) { g++ tut3.cpp -o tut3 } ; if ($?) { .\tut3 } Hello World6 PS D:\C++>

"Hello World" Program in C++

Image
  #include <iostream> int main () {     std ::cout << "Hello World" ;     return 0 ; } OUTPUT: PS D:\C++> cd "d:\C++\" ; if ($?) { g++ tut1.cpp -o tut1 } ; if ($?) { .\tut1 } Hello World PS D:\C++>