GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing codescracker.com — C++ Identifiers and Keywords with Examples
C++ Identifiers and Keywords with ExamplesIn this article, you will learn about "identifiers" and "keywords," the two most important topics when discussing C++ programming. So, without further ado, let us start with the identifiers. What are identifiers?Identifiers are the basic building blocks of a program. Identifiers are used as a general name given to different parts of the program, namely variables, objects, classes, functions, arrays, etc. Since C++ is a case-sensitive language, therefore, "codescracker," "Codescracker," "CodesCracker," and "CODESCRACKER" are all four different identifiers. Before moving further, let's first understand the rules for creating an identifier in C++. Rules to create or name an identifier in C++To create an identifier in the C++ language, you need to follow the following rules:
Following is a list of some valid identifiers. This list is included for your convenience because examples help to make the topic more understandable.
Tip: You may either use underscore in variable names to separate parts of the name, such as last_name, first_name, and main_balance, or you may go for "capital style" notation, such as lastName, firstName, and mainBalance, i.e., capitalizing the first letter of the next word. C++ Identifiers ExampleThe following C++ program is an example program of C++ identifiers that will give you an idea of how identifiers are used in C++ programming: #include<iostream>
using namespace std;
int main()
{
char ch;
char name[20];
int num;
cout<<"Enter a character: ";
cin>>ch;
cout<<"You entered: "<<ch<<endl;
cout<<"\nEnter your name: ";
cin>>name;
cout<<"Your name is: "<<name<<endl;
cout<<"\nEnter a number: ";
cin>>num;
cout<<"You entered: "<<num<<endl;
return 0;
}
When the above C++ program is compiled and executed, it will produce the following output: Now supply the input, say "c," as a character, and hit the "ENTER" key. Then supply another input, say "codescracker," as a name, and again hit the "ENTER" key. The following snapshot shows the sample run of the above C++ example program. The Keywords in C++To a language compiler, certain words have a heightened significance, and these are known as keywords. Because these are reserved words that are used for specific purposes, you are not allowed to use them as regular identifier names. I previously stated that reserved words or keywords may not be used as identifiers. As a result, it is critical to remember the list of keywords so that you do not accidentally use them as identifiers. As C++ keywords, keep the following list in mind:
More Examples« Previous Tutorial Next Tutorial » Practice Quizzes
Test your programming and computer science knowledge with interactive MCQs and topic-based quizzes. Popular Topics
Explore the most popular programming and computer science tutorials on CodesCracker. |
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |