1 / 10

Tutorial 2

Tutorial 2. By : Shruti Rathee. Identifiers. The names of the things that appear in program is known as identifier. It must start with a letter or an underscore. It cannot start with a digit. An identifier cant be the same name of reserved keywords such as else, enum,do,double . Example :.

altessa
Download Presentation

Tutorial 2

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Tutorial 2 By : ShrutiRathee

  2. Identifiers • The names of the things that appear in program is known as identifier. • It must start with a letter or an underscore. It cannot start with a digit. • An identifier cant be the same name of reserved keywords such as else, enum,do,double.

  3. Example : Here ``i`` and ``sum`` are the identifiers. • #include <iostream> using namespace std; int main() { inti,sum; cout << “enter value for i" ; cin >>i; cout << “enter value for sum" ; cin >>sum; cout << “The value for i is" <<i<<endl; cout << “The value for sum is" <<sum<<endl; return 0; }

  4. Variables • These are used to store the values that can be used later in the program. • They are called variables as their value can be changed.

  5. Example : • #include <iostream> using namespace std; int main() { inti; i=10; cout << “i = " <<i<<endl; i=5; cout << “i = " <<i<<endl; return 0; } Here the output will be something like : i=10 i=5

  6. Variable Types in c++

  7. Example • int a = 2; // initializing a. • byte b = 45; // initializes b. • double pi = 3.14159; // declares an approximation of pi. • char x = 'x'; // the variable x has the value 'x'. • For example refer program from Dr. Talla Website

  8. Loops in C++ • There are some kind of loops we have in c++ like : • The while loop. • The do-while loop. • The for loop. • In this tutorial we will cover for loop.

  9. For loop • The syntax of for loop is : for (initial-action;loop-continuation-condition;action-for-each-iteartion) { statement (a); } • Simply we can use it as : for (i=initial value; i<endvalue;i++) { // whatever you want to do in your loop }

  10. Example • inti; for (i=0;i<10;i++) { cout<<“Hi good evening\n”; } this will print Hi good evening 10 times.

More Related