Happy Codings - Programming Code Examples
Html Css Web Design Sample Codes CPlusPlus Programming Sample Codes JavaScript Programming Sample Codes C Programming Sample Codes CSharp Programming Sample Codes Java Programming Sample Codes Php Programming Sample Codes Visual Basic Programming Sample Codes


C++ Programming Code Examples

C++ > Beginners Lab Assignments Code Examples

Write a program in C++ to check the upper and lower limits of integer.

/* Write a program in C++ to check the upper and lower limits of integer. */ #include <iostream> #include <climits> // integer limits in header file using namespace std; int main() { cout << "\n\n Check the upper and lower limits of integer :\n"; cout << "--------------------------------------------------\n"; cout << " The maximum limit of int data type : " << INT_MAX << endl; cout << " The minimum limit of int data type : " << INT_MIN << endl; cout << " The maximum limit of unsigned int data type : " << UINT_MAX << endl; cout << " The maximum limit of long long data type : " << LLONG_MAX << endl; cout << " The minimum limit of long long data type : " << LLONG_MIN << endl; cout << " The maximum limit of unsigned long long data type : " << ULLONG_MAX << endl; cout << " The Bits contain in char data type : " << CHAR_BIT << endl; cout << " The maximum limit of char data type : " << CHAR_MAX << endl; cout << " The minimum limit of char data type : " << CHAR_MIN << endl; cout << " The maximum limit of signed char data type : " << SCHAR_MAX << endl; cout << " The minimum limit of signed char data type : " << SCHAR_MIN << endl; cout << " The maximum limit of unsigned char data type : " << UCHAR_MAX << endl; cout << " The minimum limit of short data type : " << SHRT_MIN << endl; cout << " The maximum limit of short data type : " << SHRT_MAX << endl; cout << " The maximum limit of unsigned short data type : " << USHRT_MAX << endl; cout << endl; return 0; }

#include is a way of including a standard or user-defined file in the program and is mostly written at the beginning of any C/C++ program. This directive is read by the preprocessor and orders it to insert the content of a user-defined or system header file into the following program. These files are mainly imported from an outside source into the current program. The process of importing such files that might be system-defined or user-defined is known as File Inclusion. This type of preprocessor directive tells the compiler to include a file in the source code program.

A program shall contain a global function named main, which is the designated start of the program in hosted environment. main() function is the entry point of any C++ program. It is the point at which execution of program is started. When a C++ program is executed, the execution control goes directly to the main() function. Every C++ program have a main() function.

The cout is a predefined object of ostream class. It is connected with the standard output device, which is usually a display screen. The cout is used in conjunction with stream insertion operator (<<) to display the output on a console. On most program environments, the standard output by default is the screen, and the C++ stream object defined to access it is cout. The "c" in cout refers to "character" and "out" means "output". Hence cout means "character output". The cout object is used along with the insertion operator << in order to display a stream of characters.

A return statement ends the processing of the current function and returns control to the caller of the function. A value-returning function should include a return statement, containing an expression. If an expression is not given on a return statement in a function declared with a non-void return type, the compiler issues an error message. If the data type of the expression is different from the function return type, conversion of the return value takes place as if the value of the expression were assigned to an object with the same function return type.

The C++ comments are statements that are not executed by the compiler. The comments in C++ programming can be used to provide explanation of the code, variable, method or class. If we write comments on our code, it will be easier for us to understand the code in the future. Also, it will be easier for your fellow developers to understand the code. By the help of comments, you can hide the program code also. There are two types of comments in C++: • Single Line comment. • Multi Line comment

Consider a situation, when we have two persons with the same name, jhon, in the same class. Whenever we need to differentiate them definitely we would have to use some additional information along with their name, like either the area, if they live in different area or their mother's or father's name, etc. Same situation can arise in your C++ applications. For example, you might be writing some code that has a function called xyz() and there is another library available which is also having same function xyz(). Now the compiler has no way of knowing which version of xyz() function you are referring to within your code.








To check whether the input alphabet is vowel or not a vowel in C++, Enter a Character, then check the character for Vowel. The character is vowel, only if it's equal to a, A, e, E, i, I, o, O