




























































































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Basic of Computer Programming C++
Typology: Essays (university)
1 / 100
This page cannot be seen from the preview
Don't miss anything!





























































































/* Simple hello world program*/
int main() { cout << “Hello World!”; //C++ statement return 0 ; } Note: Technically, in C or C++ main function has to return a value because it is declared as "int main“ which means "main function should return integer data type“ if main is declared like "void main", then there's no need of return
◦ Only alphabet characters, digits and underscore are permitted. ◦ The name cannot start with digit. ◦ Uppercase and lowercase letters are distinct. ◦ A declared keyword cannot be used as a variable.
signed: - 2147483648 to
◦ Basis for OOP. ◦ Classes enable to combine data and procedures.
◦ It provides a way to attaching names to the numbers ◦ Increase comprehensibility of the code. ◦ Alternative mean for creating symbolic constants ◦ Enumerates a list of words by assigning them values 0 , 1 , 2 and so on. enum shape {circle, square, triangle}; enum colour {red, blue= 4 , green= 8 };
Functions Set of statements to perform specific tasks. Pointers
Since pointers only hold addresses, when we assign a value to a pointer, the value has to be an address. To get the address of a variable, we can use the address-of operator (&): int nValue = 5; int *pnPtr = &nValue; // assign address of nValue to pnPtr Conceptually, you can think of the above snippet like this: int nValue = 5; int *pnPtr = &nValue; // assign address of nValue to pnPtr cout << &nValue << endl; // print the address of variable nValue cout << pnPtr << endl; // print the address that pnPtr is holding On the author’s machine, this is printed: 0012FF7C 0012FF7C
◦ 123 //decimal integer ◦ 12.34 //floating point integer ◦ 037 //octal integer ◦ 0x2 //Hexa decimal ◦ “C++” //string constant ◦ ‘A’ //character constant ◦ L’ab’ //wide-character constant
◦ const float pi = 3. 14 ;
◦ enum{x,y,z}; ◦ enum{x= 200 ,y= 300 ,z= 400 }; ◦ enum{off,on};