Cse 2541 advanced c programming
This presentation is the property of its rightful owner.
Sponsored Links
1 / 14

CSE 2541 – Advanced C Programming PowerPoint PPT Presentation


  • 78 Views
  • Uploaded on
  • Presentation posted in: General

CSE 2541 – Advanced C Programming. Instructor: Matt Boggus [email protected] Course info. Prereq – CSE 2221 or CSE 222 Co- req – CSE 2231 Website – http://www.cse.ohio-state.edu/~boggus/2541.html. Brief history of C. 1970’s Unix C, from BCPL (Thompson and Ritchie )

Download Presentation

CSE 2541 – Advanced C Programming

An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -

Presentation Transcript


Cse 2541 advanced c programming

CSE 2541 – Advanced C Programming

Instructor: Matt Boggus

[email protected]


Course info

Course info

  • Prereq – CSE 2221 or CSE 222

  • Co-req – CSE 2231

  • Website – http://www.cse.ohio-state.edu/~boggus/2541.html


Brief history of c

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


Why c

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


Why c1

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)


C characteristics

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


C vs java

C vs. Java

  • Speed

  • Portability

  • Object orientation


C vs java1

C vs. Java

  • Pointers to memory

  • Platform dependent types

  • Programmer allocated memory

  • Declare variables at start of block

  • References to objects

  • Types have well defined sizes

  • Automatic garbage collection

  • Declare variable anywhere


Hello world code

Hello World – code

/* Hello World! */

#include <stdio.h>

int main()

{

printf(“Hello World!\n”);

return 0;

}


C compilation model

C compilation model


Hello world walkthrough

Hello World – walkthrough

  • C program: hello.c

    • emacs, vi, vim, pico, joe …

    • Plaintext only

  • Preprocessing: hello.s, assembly code

    • cc -S hello.c

  • Compilation: 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


Hello world content breakdown

Hello World – content breakdown

  • Comment

  • Preprocessor directive

  • Function definition

  • Output statement

  • Return clause


Cse 2541 advanced c programming

Second Example

#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 content breakdown

Second example – content breakdown

  • Variables

  • Function calls

    • Input

    • Output

  • Operators

  • Typecasting


  • Login