codescracker


c++

C++ Punctuators



« Previous Tutorial Next Tutorial »


The following characters are used as punctuators (also known as separators) in C++ :

[ ]   ( )   { }   ,   ;   :   *   ...   =   #

Let's discuss all the above separators one by one :

C++ Punctuators Example

Following is the example program of C++ punctuators :

/* C++ Punctuators Example */

#include<iostream.h>
#include<conio.h>

int add(int, int);

void main()
{
	clrscr();

	char name[20];    // uses Brackets [] Punctuator
	int num;

	cout<<"Enter your name :";
	cin>>name;
	cout<<"Your name is "<<name<<"\n";

	int num1, num2, sum;

	cout<<"Enter two number :";
	cin>>num1>>num2;

	sum = add(num1, num2);    // uses Parentheses() Punctuator

	cout<<"Sum of "<<num1<<" and "<<num2<<" is "<<sum<<"\n";

	cout<<"Enter a Number : ";
	cin>>num;

	/* following uses Braces {} Punctuator */
	if(num>50)
	{
		if(num>500)
		{
			cout<<"Its too high!!";
		}
		else
		{
			cout<<"Its high!!";
		}
	}
	else
	{
		cout<<"Its too low";
	}

	getch();
}
int add(int a, int b)
{
	return a+b;
}

When the above C++ program is compile and executed, it will produce the following output:

c++ punctuators separators

More Examples

Here are some more C++ programs listed, using some C++ punctuators, that you can go for:


« Previous Tutorial Next Tutorial »



Tools
Calculator

Quick Links
Signup - Login - Give Online Test