


















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
C++ basics for beginners to learn from starts
Typology: Study notes
1 / 26
This page cannot be seen from the preview
Don't miss anything!



















int myNum = 5; // Integer (whole number) float myFloatNum = 5.99; // Floating point number double myDoubleNum = 9.98; // Floating point number char myLetter = 'D'; // Character bool myBoolean = true; // Boolean string myText = "Hello"; // String
A constant is a named data item with a predefined value. You cannot change the value assigned to a predefined constant. The predefined constants are: NULL: An empty reference. Similar to an empty pointer. Note that this is not the same as a null string
. TRUE : Equivalent to the number 1. FALSE: Equivalent to the number 0.
The general rules for naming variables are: Names can contain letters, digits and underscores Names must begin with a letter or an underscore (_) Names are case sensitive (myVar and myvar are different variables) Names cannot contain whitespaces or special characters like !, #, %, etc. Reserved words (like C++ keywords, such as int) cannot be used as names
As with comparison operators, you can also test for true (1) or false (0) values with logical operators. Logical operators are used to determine the logic between variables or values:
Assignment operators are used to assign values to variables. In the example below, we use the assignment operator (=) to assign the value 10 to a variable called x : Example int x = 10; int z = 50; x += 5;
C++ Comments C++ Comments Comments can be used to explain C++ code, and to make it more readable. It can also be used to prevent execution when testing alternative code. Comments can be singled- lined or multi-lined. Single-line Comments C++ Multi-line Comments
C++ Multi-line Comments Multi-line comments start with /* and ends with /. Any text between / and / will be ignored by the compiler: Example / The code below will print the words Hello World! to the screen, and it is amazing */ cout << "Hello World!";
Difference between Source code & object code 1. Source Code: Source code refers to high level code or assembly code which is generated by human/programmer. Source code is easy to read and modify. It is written by programmer by using any High Level Language or Intermediate language which is human- readable. Source code contains comments that programmer puts for better understanding.
Keywords Keywords(also known as reserved words ) have special meanings to the C++ compiler and are always written or typed in short(lower) cases. Keywords are words that the language uses for a special purpose, such as void , int , public , etc. It can’t be used for a variable name or function name or any other identifiers. The total count of reserved keywords is 95. Below is the table for some commonly used C++ keywords.
2:write a c program to find area and circumference of circle #include