Basics
for C++ language:
To write a c++ program, the following details, are need.
To write a c++ program, the following details, are need.
1.
Command-line:
- It describes what's going on inside a program, so that person looking at the source code does not have a hard time figuring it out.
- Types of comments:
(i) Single
line comments:
Syntax:
/*Statements*/
Example:
/* This is the addition program*/
(ii) Multiline comments:
Syntax:
//Statement
2.Variables:
- A variable is nothing but it allocates the memory space and holds the values.
- That means every memory of address is difficult to use in the program, conversely, we give that address as a simple user-defined word or character is called variable.
- For example, each user dials the call using a contact name only not use the phone number. i.e. each user needs an easy way to access the phone number to make a call to others.
- Here, the phone number act as a memory address and saved details of contacts called variables(this process happens in CPU).
Syntax:
Data_type variable_name;
Example:
int x, y;
Rules
for naming the variables:
- The first character must be an alphabet or an underscore(_).
- No commas or blank spaces are allowed within a variable name.
- No special symbols, an underscore can be used in a variable name.
Scope
of variables:
- It implies the availability of variables within the program.
- It is divided into two types.
(i) Local variable:
- The variables which are defined inside the function block called a local variable.
Example:
void main()
{
int a,b;//local
variable
......
}
(ii) Global variable:
- The variables that are declared before the main() a function is called a global variable.
Example:
int a,b;//Global
variable
void main()
{
......
}
3.Data
types:
- The data type is the type or kind of data, that is going to process within the program.
- There are two types of data types.*Pre-defined data type*User-defined data type
- The most widely used data types are
2. User-defined data types:
(i) Type declaration:
- It is used to allow the user to define an identifier that would represent an existing data type.
Syntax:
typedef data_type identifier;
Example:
typedef int marks;
marks m1,m2,m3;
(ii) Enumerated data type:
- It is used to create user-defined data types i.e. the programmer can create their own data type and define what values the variables of those data types can hold.
Syntax:
enum enum _name{value 1,value 2, ......,value n};
Example:
enum day{mon,tue,wed,...sun};
4. Input
function:- This function is used to get value from users.
Syntax:
cin>>variable_name;
5.Output
function:
- This function is used to show details on the output screen for user understanding.
Syntax:
cout<<“Statements”;
6.Escape
sequence:
No comments:
Post a Comment