C to C++ - Migration from C to C+ Type checking is more...

Info iconThis preview shows pages 1–8. Sign up to view the full content.

View Full Document Right Arrow Icon
Migration from C to C++
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Type checking is more precise in C++ In C++ you cant : void F(unsigned char *x); char a[]=“test”; F(a);
Background image of page 2
You can define variables wherever you need in C++ You can use // for one line comments Int numStudents; //for number of students
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
using statements Eliminate the need to use the std:: prefix Allow us to write cout instead of std::cout To use the following functions without the std:: prefix, write the following at the top of the program using std::cout; using std::cin; using std::endl;
Background image of page 4
Stream operators << for output >> for input #include <iostream.h> cin >> x >> y; cout << x << “---” << y;
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Default arguments If function parameter omitted, gets default value Can be constants, global variables, or function calls If not enough parameters specified, rightmost go to their defaults Set defaults in function prototype int defaultFunction( int x = 1, int y = 2, int z = 3 ); void f(int x,int y=g());
Background image of page 6
1. Function prototype 2. Print default volume 2.1 Print volume with one 1 // Fig. 3.23: fig03_23.cpp 2 // Using default arguments 3 #include <iostream> 4 5 7 8 int boxVolume( int length = 1, int width = 1, int height = 1 ); 9 10 int main() 11 { 12 cout << "The default box volume is: " << boxVolume() 13 << "\n\nThe volume of a box with length 10,\n" 14 << "width 1 and height 1 is: " << boxVolume( 10 ) 15 << "\n\nThe volume of a box with length 10,\n" 16 << "width 5 and height 1 is: " << boxVolume( 10, 5 ) 17 << "\n\nThe volume of a box with length 10,\n"
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 8
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 11/21/2010 for the course COMPUTER S 002 taught by Professor Ramtinkhosravi during the Spring '10 term at Amirkabir University of Technology.

Page1 / 25

C to C++ - Migration from C to C+ Type checking is more...

This preview shows document pages 1 - 8. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online