CS304: Lecture 1 - PowerPoint PPT Presentation

1 / 11
About This Presentation
Title:

CS304: Lecture 1

Description:

CS304: Lecture 1. Basics of C Programming. Deitel, Ch. 1-2. http://www.cis.uab.edu/cs304 ... ie/~renaat/projects/cvjava.html. Typical C Environment. Hello ... – PowerPoint PPT presentation

Number of Views:102
Avg rating:3.0/5.0
Slides: 12
Provided by: faizan
Category:
Tags: basics | cs304 | html | lecture

less

Transcript and Presenter's Notes

Title: CS304: Lecture 1


1
CS304 Lecture 1
  • Basics of C Programming
  • Deitel, Ch. 1-2
  • http//www.cis.uab.edu/cs304

2
Overview
  • Who am I?
  • Who are you?
  • What is this course?

3
C vs. Java
  • C extension of C
  • Provides capabilities for object-oriented
    programming
  • Hybrid language
  • C-like style
  • Can have global functions or data. Java cant
    (Everything must be in a class)
  • OO style (Nouns Classes , Verbs Functions)
  • Fast
  • Originally designed for OS development, can be 20
    times faster than Java.
  • Complex
  • Preprocessor Appendix F (pp. 1272)
  • Macro, templates, operator overloading
  • And more
  • Check this link for more C vs. Java
  • http//www.compapp.dcu.ie/renaat/projects/cvj
    ava.html

4
Typical C Environment
5
Hello World!
  • include ltiostreamgt // preprocessor directive
  • using stdcout // scope operator
  • int main()
  • cout ltlt "Hello, world!\n" // stream operator
  • return 0

6
Structure of a C Program
  • Comments
  • Single-line comment
  • Begin with //
  • Preprocessor directives
  • Processed by preprocessor before compiling
  • Begin with

7
Structure of a C Program
  • Standard output stream object
  • stdcout
  • Connected to screen
  • ltlt
  • Stream insertion operator
  • Value to right (right operand) inserted into
    output stream
  • Input stream object
  • gtgt (stream extraction operator)
  • Used with stdcin
  • Waits for user to input value, then press Enter
    (Return) key
  • Stores value in variable to right of operator
  • Converts value to variable data type

8
Structure of a C Program
  • Namespace
  • std specifies using name that belongs to
    namespace std
  • std removed through use of using statements
  • using statements
  • Eliminate use of std prefix
  • Write cout instead of stdcout

9
Fundamental Types
  • Numbers int, float, double
  • Qualifiers short or long, signed or unsigned
  • Size in bytes (on the blazers)
  • char 1 (What is a char, anyway?)
  • short int 2
  • int 4
  • long int 4
  • float 4
  • double 8
  • long double 16
  • See Appendix B (pp. 1232) for full list of
    fundamental types

10
An Example
  • include ltiostreamgt
  • using namespace std
  • int main()
  • // testing the size of each type
  • cout ltlt "char\t" ltlt sizeof(char) ltlt endl
  • cout ltlt "short int\t" ltlt sizeof(short int) ltlt
    endl
  • cout ltlt "int\t" ltlt sizeof(int) ltlt endl
  • cout ltlt "long int\t" ltlt sizeof(long int) ltlt
    endl
  • cout ltlt "float\t" ltlt sizeof(float) ltlt endl
  • cout ltlt "double\t" ltlt sizeof(double) ltlt endl
  • cout ltlt "long double\t" ltlt sizeof(long
    double) ltlt endl
  • // testing the unsigned qualifier
  • unsigned short int n -1
  • cout ltlt n ltlt endl // ??? What is the output
    1111 1111 1111 1111
  • n -2
  • cout ltlt n ltlt endl // ??? And this one
    1111 1111 1111 1110

11
Arithmetic and Relational Operations
  • Arithmetic The standards , -, /, , , ()
  • They work the way Java programmers expect
  • Relational gt, gt, lt, lt, , !
  • Same goes
Write a Comment
User Comments (0)
About PowerShow.com