C++ Syntax
Let's understand the following code:
Code:-
Line 1 : #include <iostream> Line 2 : using namespace std; Line 3 : int main() { Line 4 : cout << "Hello World!"; Line 5 : return 0; Line 6 : }
Example Explained
Line 1: iostream is standard input output stream. This is a header file that is available in C++ for input output operation.
Line 2: std is the standard namespace. It defines cout, cin and many other things.
Line 3: A special function "main", which denotes the beginning of a program. Code between the {curly braces} will be executed.
Line 4: Cout is a type of object in C++ that is used to print text to the output screen. In our example it will output "Hello World".
Note: Every C++ statement will have a semicolon at the end ';'
Remember: The white space will be ignored by the compiler and multiple white spaces can help you read the code easily.
Line 5: return represents the end of the function.
Exercise:-
1. return 0 represent?
View Answer
2. What will be the output of the following?
cout << "Letsfindcourse!";
View Answer
Program :-
C++ Program to Find Quotient and Remainder
#include <iostream> using namespace std; int main() { int divisor, dividend, quotient, remainder; cout << "Enter dividend: "; cin >> dividend; cout << "Enter divisor: "; cin >> divisor; quotient = dividend / divisor; remainder = dividend % divisor; cout << "Quotient = " << quotient << endl; cout << "Remainder = " << remainder; return 0; }
Output :
Enter dividend: 13 Enter divisor: 4 Quotient = 3 Remainder = 1
Visit :
Discussion