Skip to content
Menu
Code for Java c
  • Home
  • Java
    • Java Examples
    • Java tutorials
  • C
    • C tutorials
    • C Examples
  • C++
    • C++ Tutorials
    • C++ Examples
  • Python
    • Python Tutorials
    • Python Examples
  • About
    • About me
    • contact us
    • disclaimer
    • Privacy Policy
Code for Java c

Some simple example programs in C++ language

Posted on July 10, 2016January 29, 2020

Some Simple example program in C++ language

In this tutorial, we will discuss the Some simple example program in C++ language

C++ is one of the object-oriented program similar java

C++ programming language defines several Header files similar C. That contains much useful information run your program, generally, we can use <iostream> header file

Using namespace std;  instruct the compiler to use the std namespace

main ()– main() is the main function and program execution begins. That is a beginning point in C++ 

cout<< – This is to use to display the output on the screen

return 0 – this is to help to terminate the main function and then return the value 0

C++ first program


 Here, Some C++ programs and their outputs

First Program

Helloworld program

Some example program in C++ language
Example 1

When the above code is compiled and executed, it produces the following result:

Some example program in C++ language
Output

C++ second program

Variable assignment and display default value

#include <iostream>

using namespace std;
int main()
{    
int age;   
 float average;   
 char sex;    
bool isit;   
 cout << age << endl << average << endl << sex << endl << isit << endl;    
return 0;   
 }

When the above code is compiled and executed, it produces the following result:

Some example program in C++ language
Example 2



out put some garbage values

C++ third program

variable assignment and display given value

#include <iostream>

using namespace std;

int main()
{
    int age=23;
    float average=22.52;
    char sex='m';
    bool isit=true;

    cout << age << endl << average << endl << sex << endl<< isit<< endl;
    return 0;
}

 

When the above code is compiled and executed, it produces the following result:

Some example program in C++ language
Example 3

output the assigned value.

C++ forth program

Display the value using cout in C++ language

using the cout

#include <iostream>

using namespace std;

int main()
{
    cout << "Hello this is using cout in C++" << endl;
    return 0;

}

 

When the above code is compiled and executed, it produces the following result:

Some example program in C++ language
Example 4

bio data using cout

#include <iostream>
using namespace std;
int main()

{

int age=35;
int dob=19770805;
int icno=772182503;

    cout <<"Hello my name is jhon"<<endl<<"my age is "<<age<< endl
    <<"my dob is "<<dob<< endl
    <<"my ic no is "<<icno<< endl<< "ya this is my biodata"<<endl;
    return 0;

}

 


When the above code is compiled and executed, it produces the following result:

Some example program in C++ language
Example 5

 

C++ fifth program

Takes input from thr user

using cin

#include <iostream>

using namespace std;

int main()
{
    int age;
    int marks;
    float avg;
    cout << "enter your age and average and marks "<< endl;
    cin >> age >> avg >> marks;
    cout << "you have entered age is "<< endl << age<< endl << "average is "
    << endl << avg << endl <<"marks is " << endl<< marks << endl;
    return 0;

}



Some example program in C++ language
Program 6

When the above code is compiled and executed, it produces the following result:

Some example program in C++ language
Output

C++ sixth program

Arithmetic operation in C++

#include <iostream>

using namespace std;

int main()
{
    int num1=10 , num2=20;
    cout << num1 <<"+"<<num2<<"="<<num1+num2<< endl;
    cout << num1 <<"-"<<num2<<"="<<num1-num2<< endl;
    cout << num1 <<"*"<<num2<<"="<<num1*num2<< endl;
    cout << num1 <<"/"<<num2<<"="<<num1/num2<< endl;

    return 0;
}

 

When the above code is compiled and executed, it produces the following result:

Some example program in C++ language
Program 7

C++ seventh program

increment and decrement operators

prefix – ++a or –a
postfix – a++ or a–

#include <iostream>

using namespace std;

int main()
{
    int a=10;
    a++;
    cout << a<<endl;
    a--;
    cout << a <<endl;;

    return 0;

}

 



When the above code is compiled and executed, it produces the following result:

Some example program in C++ language
program 8

 

Using assignment operator

 

#include <iostream>
using namespace std;

int main()
{
int a;
int b=3;
a=b;
a+=2;

cout << a;
return 0;

}

 

 

When the above code is compiled and executed, it produces the following result:

 

 

Suggested for you
The operator in C++ language
Hello world in C++ program

Related

Recent Posts

  • Subtract two numbers using method overriding
  • PHP Star triangle Pattern program
  • Using function or method to Write temperature conversion : Fahrenheit into Celsius
  • Function or method:temperature conversion from Fahrenheit into Celsius – Entered by user
  • Write temperature conversion program: Fahrenheit into Celsius
  • How to write a program to convert Fahrenheit into Celsius

tag

Addition (6) Array (38) C++ language (91) C language (98) c sharp (23) Division (6) Function (29) if else (32) Java language (102) JavaScript (5) loops (137) Multiply (7) Oop (2) patterns (65) PHP (13) Python Language (38) Subtraction (7) temperature (20)

Archives

Categories

Address

Global information technology

Puloly south, PointPedro

Jaffna

Srilanka

©2025 Code for Java c | Powered by SuperbThemes