CPP Review note

The “Hello World” Program

C version:

1
2
3
4
5
6
#include <stdio.h>
int main(int argc, char* argv[])
{

printf("Hello world!\n");
return 0;
}

C++ version:

1
2
3
4
5
6
#include <cstdio>
int main(int argc, char* argv[])
{

printf("Hello world!\n");
return 0;
}

Sizes of types

  • The size of types (in bits/bytes) can vary in C/C++
    • For different compilers/operating systems
    • In Java, sizes are standardised, across O/Ss
  • An int changes size more than other types!
    – Used for speed (not portability), but VERY popular! (fast) – Uses the most efficient size for the platform
    – 16 bit operating systems usually use 16 bit int
    – 32 bit operating systems usually use 32 bit int
    – 64 bit operating systems usually use 64 bit int
  • sizeof() operator exists to tell us the size