CS 102 (Fall '03)
[Schedule] [Examples] [Programs] [Notes & Reference] [Syllabus] [Lab & TA] [Tests] [Grades]

Differences Between C and C++

Concept C

C++

I/O printf, scanf cin, cout (using streams)
formatting output format string, E.g.
        printf("%5.2f", floatingPointValue);

setting flags. E.g.
        cout.setf(ios::fixed);
        cout.setf(ios::showpoint);
        cout.precision(2);
        cout<< floatingPointValue;

Variable declaration At beginning of each function

Anywhere in function
Can also be done within a for loop such as:
        for( int i; i<LIMIT; i++) {..... }

Variable initialization Using equals sign, e.g. int x = 3; Using constructor, e.g. int x(3);
Reference Parameters Pass with &, catch with *, use with * Catch with &
Program name *.c *.C or *.cpp or *.cc
Creating structure instances if "struct node" is declared, that subsequent uses also require the type to be "struct node". Once "struct node" is declared, we can subsequently simply use "node" as the type.
Dynamic Memory allocation/deallocation malloc / free new / delete
Including standard system libraries #include <stdio.h>

#include <iostream>
using namespace std;

 


[CS Dept] [UIC] [Prof. Reed]