Presentation is loading. Please wait.

Presentation is loading. Please wait.

C Stuff CS 2308.

Similar presentations


Presentation on theme: "C Stuff CS 2308."— Presentation transcript:

1 C Stuff CS 2308

2 Major differences between C and C++
Header files When including libraries, include the “.h” #include <string.h> No Constants Typically use #define to identify constants Different I/O libraries Use <stdio.h> printf and scanf instead of cout and cin Strings No strings in C

3 C strings There is no “string” data type in C Use arrays of characters
Always null terminated “\0” Need one more space than the number of characters you need to store. char name[26]; /*to hold 25 chars and null */ No direct comparison for equality or direct assignment NO str1 = str2 NO str1 == str2 OR str1 < str2

4 String functions in C Found in <string.h> Examples
Page in text Examples strcpy strcmp strlen strcat atoi atof itoa

5 Other differences between C and C++
No namespaces Not a real issue for the types of programs we are creating, but important for larger projects. No “pass by reference” Very important. Let’s see how we can make functions work without it. No bool data type Because of the frequency of boolean expressions we typically find a way to use a simulated type. #define FALSE 0 #define TRUE 1

6 More differences between C and C++
No const qualifier All variables must be declared in functions before the first executable statement No function overloading Serious drawback for object-oriented programming

7 Command Line Arguments
As you have seen in Linux, there are often command line arguments to programs. How do we use them in programs? “argc” is the number of arguments “argv” is an array of strings int main (int argc, char* argv[]) { }


Download ppt "C Stuff CS 2308."

Similar presentations


Ads by Google