CSE342: Fundamentals of Internetworking

C Programming Review

Prof. Brian D. Davison

Computer Science & Engineering, Lehigh University

Accessing the Suns

Accessing the Suns

Demonstrate use of ssh.

Hello World

GNU Emacs

Operating Emacs

Essential Commands

Essential Commands

Files Created By Emacs

Using UNIX

Using UNIX

info is a subset of emacs; info info to get started; man man; man is better than Google -- specific to your OS and installation Note the man page sections for the system calls. Use man -s to specify which section of the manual pages to search.

Using UNIX Shells

Finished Using UNIX...

Any questions?

Let's move on to C

The C Programming Language

C versus C++

Do the students know?

Major C differences from C++

Other Differences

So what stays the same? Glad you asked...

Basic C Data Types

int is signed, 32 bits on typical (but not all) platforms. float typically 32bits, double typically 64, long double 128

Operators

As always, multiplication and division have precedence over addition/subtraction; use parenthesis to make things clear

Assignment Operators

Type Conversions

Quick test: what is the result of 1.0 + 3/2?

Control Flow

Control Flow

C Arrays

Character Arrays

C Strings

Let's write code to concatenate two strings. Here is a skeleton that we can fill out.
Single quote for char constants, double quotes for strings. Must be null terminated. What is a null?

Using strings in C

Using strings in C

Using strings in C

Structures

Structures

C libraries use structs

Pointers

Pointers

Pointers

Parameters in C Functions

What is call-by-value? Show example prog8-10.c

Pointer Declarations

Pointer Declarations

Pointer arithmetic

String operations using pointers

Null pointers

Null pointers

Pointers and arrays

Fun, eh?

Strings as pointers

Strings as pointers

Pointers and Storage

Static vs. Dynamic Allocation

Note the cast from malloc() -- this is because malloc returns void *

Why dynamic allocation?

Why dynamic allocation?

How much to allocate?

Potential Problem

Nothing "potential" here -- this is definitely a problem.

Returning memory

Returning memory

Functions that return pointers

Generally, either you need to free() or this is memory that you have no control over...

User-Defined Structures

Access to Structs

User-defined types