0% found this document useful (0 votes)
5 views9 pages

Lesson 1.2 (Intro To C++)

The document provides an introduction to C++ programming, highlighting the differences between old and new versions of the language, including changes in input/output commands and the use of namespaces. It explains the scope resolution operator for accessing global variables and discusses variable declaration flexibility. Additionally, it covers comment syntax in C++, including multi-line and single-line comments.

Uploaded by

SH Shihab
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views9 pages

Lesson 1.2 (Intro To C++)

The document provides an introduction to C++ programming, highlighting the differences between old and new versions of the language, including changes in input/output commands and the use of namespaces. It explains the scope resolution operator for accessing global variables and discusses variable declaration flexibility. Additionally, it covers comment syntax in C++, including multi-line and single-line comments.

Uploaded by

SH Shihab
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 9

Introduction to C++

Dept. of Computer Science & Engineering

1
Programming with C++
 Two versions of C++
 Old version of C++  New version of C++
#include <iostream.h> #include <iostream>
int main(){ using namespace std;
/* program code */ int main(){
return 0; /* program code */
return 0;
}
}

2 Department of CSE, CUET


General form of C++ Console I/O
 Input Command: cin >> variable;
 Output Command: cout << expression;

3 Department of CSE, CUET


Namespaces

 A namespace is a declarative region that localizes the names of


 identifiers to avoid name collisions.
 The contents of new-style headers are placed in the std namespace
#include <iostream> #include <iostream>
int main() { using namespace std;
char str[16]; int main() {
std::cout << “Enter a string: ”; char str[16];
std::cin >> str; cout << “Enter a string: ”;
std::cout << “String: ” << str; cin >> str;
return 0; cout << “String: ” << str;
} return 0;
}

4 Department of CSE, CUET


Scope Resolution Operator (::)

 To access a hidden global variable


#include <iostream>
int count = 0;
int main(void) {
int count = 0;
::count = 1; // set global count to 1
count = 2; // set local count to 2
return 0;
}

5 Department of CSE, CUET


Variable Can Be Declared Anywhere!

6 Department of CSE, CUET


Bool Type

7 Department of CSE, CUET


C++ Comments

 Multi-line comments
/* one or more lines of comments */

 Single line comments


// …

8 Department of CSE, CUET


9 Department of CSE, CUET

You might also like