![]() |
C Plus Plus Keywords Programming Language |
C Plus Plus Keywords Programming Language
C Plus Plus Keywords: C++ keyword is used as an identifier in C++ programs, it is a
Keywords are most
important because they can be identified Data_Types are already defined by C
Library. Keywords are reserved words that have special meanings in the C
language.
All
the C keywords have been assigned fixed meanings and they cannot be used as
variable names. Their meaning cannot be changed.
There is a total of 55 keywords in the C++
1. Auto 2. break 3. case 4. char 5. const 6. continue 7. default 8. do 9. double 10. else 11. enum 12. extern 13. float
14. for 15. goto 16. if 17. int 18. long 19. register 20. return 21. short 22. signed 23. sizeof 24. static 25. struct 26. switch 27. typedef 28. union 29. unsigned 30. void 31. volatile 32. while 33. new 34. this 35. operator 36. throw 37. bool 38. explicit 39. private 40. true 41. export 42. protected 43. try 44. public 45. Catch 46. false 47. class 48. friend 49. default 50. inline 51. delete 52. template 53. namespace 54. virtual 55. Pointer |
Identifiers in C++ Programming Language
Rules For identifier in C++ Language
• An Identifier can only have alphanumeric characters ( a-z, A-Z, 0-9 ) and underscore( _ ).
• The first character of an identifier can only contain the alphabet( a-z, A-Z ) or underscore ( _ ).
• Identifiers are also case-sensitive in C++. For example, name and Name are two different identifiers in C++.
• Keywords are not allowed to be used as Identifiers.
• No special characters, such as semicolons, periods, white spaces, slash, or commas are permitted to be used in or as Identifier.
Constant in C++ Programming Language
Constants: C++ Constants are just like normal variables. But, the only difference is that their values can’t be modified by the program(programmer/user) once they are defined. Constants refer to fixed values. They are also called literals
Constants can be of any of the basic data types like an integer constant, a floating constant, a character constant, or a string literal. There are enumeration constants as well.
Constant Type and Data Type Example
Constant Type |
Data Types |
Integer constants |
int ( 21, 76, -78 etc ) unsigned int (5000u, 1000U, etc) long int, long long int (483,647 2,147,483,680) |
Real or Floating-point constants |
float (10.456789) |
Octal constant |
int (Example: 013 /*starts with 0 */) |
Hexadecimal constant |
int (Example: 0x90 /*starts with 0x*/) |
character constants |
char (Example: ‘P’, ‘R’, ‘G’) |
string constants |
char (Example: “C LANGUAGE”, “Codeswithbaby” |
Integer Constant in C++ Language
• An integer constant must have at least one digit.
• It must not have a decimal point or fractional part or any other symbols.
• It could be positive or negative or may be zero
• No commas or blanks are allowed within an integer constant.
• The number without a sign is assumed as positive.
• The allowable range for integer constants is -32768 to 32767.
Real Constant in C++ Language
• A real constant must have at least one digit
• It is often known as floating-point constants.
• It could be either positive or negative
• If no sign precedes an integer constant, it is assumed to be positive.
• No commas or blanks are allowed within an absolute constant.
• The real constants can be written in exponential notation, containing fractional and exponential parts. For example, the value 2456.123 can be written as 2.456 X e ^+3.
Character Constant in C++ Language
Single Character Constant in C++ Language
• A Character constant is a single character. It can also be represented with a single digit or a single special symbol or white space enclosed within a pair of single quote marks.
• The maximum length of a character constant is 1 character.
• String constants are enclosed within double quotes.
• Example: ‘a’, ‘B’, ‘-‘
• Character constants have integer values known as ASCII values. For example printf(“ %c %d”,65, ‘B’); will display characters ‘A’ and 66.
String Constant in C++ Language
• String constants are a sequence of characters enclosed within double quote marks. The string may be a combination of all kinds of symbols.
• For example: “Codeswithbaby”, “C Language”.”450”,” R”
Backslash Character Constant in C++ Language
There are Some characters' who have earnings in the C++ language. They should be preceded by a backslash symbol to make use of their special functions of them.
Given below is the list of special characters and their purpose
Backslash_character |
Meaning |
/b |
Backspace |
/f |
Form Feed |
/n |
New Line |
/r |
Carriage return |
/t |
Horizontal Tabl |
/" |
Double Quote |
/' |
Single quotes |
// |
Backslash |
/v |
vertical tab |
/a |
Aler or bell |
/? |
Question mark |
/N |
Octal constant (N is an octal constant) |
/XN |
Hexadecimal constant (N – hex.dcml cnst) |
Constants Program in C++ Language
#include <iostream> using namespace std; void main() { const int height = 100; /*int constant*/ const float number = 3.14; /*Real constant*/ const char letter = 'A'; /*char constant*/ const char letter_sequence[10] = "ABC"; /*string constant*/ const char backslash_char = '\?'; /*special char cnst*/ cout<<"value of height:"<<height ; cout<<"value of a number:"<<number; cout<<"value of letter :"<<letter; cout<<"value of letter_sequence: "<<letter_sequence; cout<<"value of backslash_char : "<<backslash_char; } *****OUTPU***** value of height: 100 value of a number: 3.140000 value of letter: A value of letter_sequence : ABC value of backslash_char:? |
Example write a Program Using #Define Preprocessor Directive in C++ Language
#include <iostream> #define height 100 #define number 3.14 #define letter 'A' #define letter_sequence "ABC" #define backslash_char '\?' void main() { cout<<"value of height : "<<height; cout<<"value of number : "<<number; cout<<"value of letter : "<<letter; cout<<"value of letter_sequence : "<<letter_sequence; cout<<"value of backslash_char : "<<backslash_char; }
*****OUTPUT***** value of height: 100 value of a number: 3.140000 value of letter: A value of letter_sequence : ABC value of backslash_char:? |
List of keywords in C++ Language
Auto: A auto keyword makes an automatic variable like. This statement suggests that data is a variable of storage class auto and datatype int. Automatic variables are local functions, they are also called local variables. so it is called an auto variable.
Break: A break keyword statement terminates the loop immediately. The break statement ends the for loop when the condition is false.
#include<iostream> using namespace std; int main() { for(int i=1;i<=10;i++) { if(i==5) { cout<<"break the 5 value of break"<<endl; break; } cout<<i<<endl; } } *****OUTPUT***** 1 2 3 4 break the 5 value of break |
Continue Statement: A continue statement skips the value of the current iteration of the loop. continue statement is a print next iteration.
How To Use Continue Statement in C++?
#include<iostream> using namespace std; int main() { for(int i=1;i<=10;i++) { if(i==5) { cout<<"skip the 5 value of continue"<<endl; continue; } cout<<i<<endl; } } *****OUTPUT***** 1 2 3 4 skip the 5 value of continue 6 7 8 9 10 |
Switch case: A switch statement is used to check the condition. The switch statement is the very most useful statement. switch statements are multiple condition checks using a switch case.
Syntax of switch Statement
switch(expression) { case '1': //case one execute ; break; case '3': //case three execute; break; default: //no case match is default case is executed; } |
How To Use Switch Statement in C++?
#include<iostream> using namespace std; int main() { int x=2; switch(2) { case 1: cout<<"case one executed"; break; case 2: cout<<"case two executed"; break; case 3: cout<<"case three executed"; default: cout<<value does not match; } } *****OUTPUT***** case two executed |
Char: A char keyword defines the only character value.
char grade='A';
How To Use Char Keyword in C++?
#include<iostream> using namespace std; int main() { char grade='A'; cout<<"Student garde value:"<<grade; } *****OUTPUT***** Student grade value:'A' |
Const: A const identifier can be declared a constant value using the const keyword. the constant value can not be changed.
const int data = 10;
How To Use const keyword in C++?
#include<iostream> using namespace std; int main() { const int data=10; cout<<"The value of data:"<<data; } *****OUTPUT***** The value of data:10 |
do-while: A do-while loop is a very useful loop. do-while loop used the repeat the value. when they do while loop the first time executes in the program given the condition.
Syntax do-while loop in C++
do { //statement; increment/decrement; } while(condition); } |
How To Use do-while loop in C++?
#include<iostream> using namespace std; int main() { int i=1; do { cout<<i; i++; } while(i<=10); } *****OUTPUT***** 1 2 3 4 5 6 7 8 9 10 |
double and float: double and float Keywords are used for declaring floating type values. double keywords are used for the long number of values and float is used for the floating-point value
double data=13.75356354;
float data=13.23;
How To Use double and float in C++?
#include<iostream> using namespace std; int main() { double data=687537332; float d=53.2364; cout<<"Value of double number:"<<data; cout<<"Value of floating number:"<<d; } *****OUTPUT***** Value of double number:687537332.000000 Value of floating number:53.236401 |
if and else: A if-else statement is used in the decision-making condition.if the statement executes the condition is true. otherwise else statements are executed. when condition false.
Syntax of if-else statement
if(condition) { //statement; } else { //statement; } |
How To Use if-else statement in C++?
#include<iostream> using namespace std; int main() { int age; if (age<=18) { cout<<"You can play the PUBG Game'; } else { cout<<"You can not play the PUBG Game"; } return 0; } *****OUTPUT***** You can play the PUBG Game |
enum: A enum is the named integer constants. enum is a user-defined data type. enum is an Enumeration.
Syntax of Enumeration
enum enum_name{value1,value2,value3....value n}; |
How To Use enum keyword in C++?
#include<iostream> using namespace std; enum year { Jan,Feb,mar,api,may,June,July,Aug,sep,Oct,Nov,dec}; int main() { enum year data; data=June; cout<<"Value of June:"<<data; } *****OUTPUT***** Value of june:5 |
for loop: A for loop can be Using C++ Language. it is the very most useful loop. Because for loop in an initiation condition and increment/decrement only one line. so for loop is the most useful loop.
Syntax of for loop
for(initiation;condition;increment) for(int i=1;i<=10;i++) |
How To Use for loop in C++?
#include<iostream> using namespace std; int main() { for(int i=1;i<=10;i++) { cout<<i; } } *****OUTPUT***** 1 2 3 4 5 6 7 8 9 10 |
extern: A extern keyword is used for external linking outside of the file.
goto: The goto statement is a jump statement control of the program to another label of the program.
int: A int keyword is used as the integer type value of the c++ Language.
return: The return keyword terminates the function and returns the value of the c++ program.
size of: A size of a keyword has been used as the size of data.
register: A register keyword is used the quick access the data. it is speedy to retrieve the data from the computer. Because value is stored in the register.
static: A static variable is not reclaimed. They keep their value. On re-entry to the block, the variable will have its old value.
struct: A struct keyword is used for declaring a structure. A structure can behold the variables of different types with only a single name.
Syntax of structure
struct student { char name[80]; float marks; int age; }s1, s2; |
typedef: The C++ programming language provides a keyword called typedef which you can use to give a type a new name.
A typedef keyword can be used for the long name to a small name change. typedef can be Using the short name of any long variables name.
union: Union is a data type in C++ programming that allows different data types to be stored in the same memory locations.
A union is used to group different variables under a single name. union is stored the single value stored. otherwise, other values are garbage values in the variables.
Syntax of union
student { Data type var1; Data type var2; Data type var3; }; |
void: Avoid keywords meaning nothing value. the void return type of the c program.
volatile: A volatile keyword is used for creating volatile objects. It can be used the change the value of hardware memory.
python language is best post in this blog
ReplyDelete