CSC 357 Lecture Notes Week 1
Introduction to the Course Introduction to C and UNIX
#include "stdio.h" /* Include standard I/O library */ main() { /* Define main function */ printf("hello, world\n"); /* Print to stdout */ }
gcc hello.c
a.out
import java.io.*; // not necessary in this case, but parallels #include "stdio.h" public class hello { // not present in C public static void main(String[] args) { // simpler in C System.out.println("hello, world"); // simpler in C } }
javac hello.java
java hello
char string_var[100]; /* a string variable that can hold up to 100 chars */
string_var[0] = 'a'; string_var[1] = 'b'; string_var[2] = 'c'; string_var[3] = '\0'; /* Null termination */
void f(char string_arg[]) { /*...*/ }
which is completely equivalent to the previous definition of function f.`void f(char *string_arg) { /*...*/ }
f("xyz");
char* string_const = "xyz";
Data type Description char a single byte, capable of holding one character in the local character set int an integer, typically reflecting the natural size of integers on the host machine float single-precision floating point double double-precision floating point
#define LINE_LENGTH 72