CSE 2541 – Advanced C Programming

CSE 2541 – Advanced C Programming - Description

Course info. Prereq. – CSE 2221 or CSE 222. Co-. req. – CSE . 2231. Website. http. ://www.cse.ohio-state.edu. /. ~shir/cse-. 2451. /. Brief history of C. 1970’s. Unix. C, from BCPL (Thompson and Ritchie. ID: 588392 Download Presentation

48K - views

CSE 2541 – Advanced C Programming

Course info. Prereq. – CSE 2221 or CSE 222. Co-. req. – CSE . 2231. Website. http. ://www.cse.ohio-state.edu. /. ~shir/cse-. 2451. /. Brief history of C. 1970’s. Unix. C, from BCPL (Thompson and Ritchie.

Similar presentations


Download Presentation

CSE 2541 – Advanced C Programming




Download Presentation - The PPT/PDF document "CSE 2541 – Advanced C Programming" is the property of its rightful owner. Permission is granted to download and print the materials on this web site for personal, non-commercial use only, and to display it on your personal computer provided you do not modify the materials and that you retain all copyright notices contained in the materials. By downloading content from our website, you accept the terms of this agreement.



Presentation on theme: "CSE 2541 – Advanced C Programming"— Presentation transcript:

Slide1

CSE 2541 – Advanced C Programming

Slide2

Course info

Prereq

– CSE 2221 or CSE 222

Co-

req

– CSE

2231

Website

http

://www.cse.ohio-state.edu

/

~shir/cse-

2451

/

Slide3

Brief history of C

1970’s

Unix

C, from BCPL (Thompson and Ritchie

)

C programming Language

Widely used like the others: Fortran, Pascal

Main form of language for system programming

Available on any machine with C compiler and

library

Slide4

Why C?

Popular

language

Operating

systems (Win, Linux, FreeBSD)

Web

servers (Apache)

Web browsers

(Fox)

Mail

servers (

sendmail

, postfix)

DNS

servers (bind)

Graphics

card programming (

OpenCL

)

Programming language rankings

Why

?

Performance

Portability

Familiar

to programmers

Slide5

Why C?

Compared to assembly language

Abstracts

the hardware view (registers,

memory, call

stacks), making code portable and easier

Provides

variables, functions, arrays,

complex arithmetic

,

Boolean

expressions

Compared

to other high-level languages

Maps

almost directly into hardware

instructions, making

optimization easier

Provides

a minimal set of abstractions

compared to

other HLLs

Like

other HLLs, makes complex

programming simpler

(at the expense of efficiency)

Slide6

C characteristics

"

C" because many features came from earlier language “B“

Reduced

form of

Basic Combined Programming Language,

1966

Block

structured

Blocks

are denoted {

}

Many

utility functions provided in libraries

Libc

,

libpthread

,

libm

Nowhere

near the functionality of other runtime

environments

Some

major C features

Functions

, Structures, Types

Pointers

– direct access to memory space

Slide7

C vs. Java

Speed

Portability

Object orientation

Slide8

C vs. Java

Pointers to memoryPlatform dependent typesProgrammer allocated memoryDeclare variables at start of block

References to objects

Types have well defined sizes

Automatic garbage collection

Declare variable anywhere

Slide9

Hello World – code

/* Hello World! */

#include <

stdio.h

>

int

main()

{

printf

(“Hello World!\n”);

return 0;

}

Slide10

C compilation model

Slide11

Hello World – walkthrough

C program:

hello.c

emacs

, vi, vim,

pico

,

joe

Plaintext only

Preprocessing

and Compiling:

hello.s

, assembly code

cc -S

hello.c

Assembler:

hello.o

, a binary file

cc -c

hello.s

Linking:

a.out

or hello, an executable file

cc

hello.o

cc -o hello

hello.o

Loading (dynamical linking) and execution: ./hello

./

a.out

./hello

Slide12

Hello World – content breakdown

Comment

Preprocessor directive

Function definition

Output

statement

Return

clause

Slide13

#include <stdio.h> int main(){ int first, second, add; float divide; printf("Enter two integers\n"); scanf("%d%d", &first, &second); add = first + second; divide = first / (float)second; printf("Sum = %d\n",add); printf("Division = %.2f\n",divide); return 0;}

Second Example

Slide14

Second example – content breakdown

Variables

Function calls

Input

Output

Operators

Typecasting