Learn C++ Online

Interested in learning C Programming? Click here...



this pointer in Cpp 1

this pointer in C++

C++ uses a unique keyword called this to represent an object that invokes a member function. this pointer in C++ is a pointer that points to the object for which this function was called. For example, the function call:

will set the pointer this to the address of the object A. The starting address is the same as the address of the first variable in the class structure. This unique pointer is automatically passed to a member function when it is called. The pointer this acts as an implicit argument to all the member functions. Consider the following simple...

Program in Cpp to find sum of first n natural numbers 1

Program in C++ to find sum of first “n” natural numbers

The below program will accept the number “n” from the user and calculates the sum of first “n” natural numbers. For example, if the input provided by the user is 5 then it will calculate the sum of first 5 natural numbers i.e., 1+2+3+4+5

Output

Note: The above program is written and tested using Microsoft Visual Studio 2008

Program in cpp to display the name of the day in a week 1

Program in C++ to display the name of the day in a week

Program in C++ to display the name of the day in a week, depending upon the number entered through the keyboard. The program will accept integer value between 1 and 7. Depending on the number entered, the program will display the name of the day as follows: 1 => “Monday” 2 => “Tuesday” 3 => “Wednesday” 4 => “Thursday” 5 => “Friday” 6 => “Saturday” 7 => “Sunday”

Output:

Note: The above program is written and tested using Microsoft Visual Studio 2008

Program in Cpp to read three numbers and compute their average 0

Program in C++ to read three numbers and compute their average

The below program will accept three numbers from the user, compute their average and display it.

Output:

Note: The above program is written and tested using Microsoft Visual Studio 2008