Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 Key Concepts:  Why C?  Life Cycle Of a C program,  What is a computer program?  A program statement?  Basic parts of a C program,  Printf() function?

Similar presentations


Presentation on theme: "1 Key Concepts:  Why C?  Life Cycle Of a C program,  What is a computer program?  A program statement?  Basic parts of a C program,  Printf() function?"— Presentation transcript:

1 1 Key Concepts:  Why C?  Life Cycle Of a C program,  What is a computer program?  A program statement?  Basic parts of a C program,  Printf() function?  Goal: Write your first C program

2 2 General Knowledge  Computer Consists of Hardware Software  Programmers

3 3 What is a computer program (software)?  Is a set of instructions that tells the computer what to do.  There are about 400 programming languages.  Each language has its own: Syntax Grammar Application

4 4 A Brief History of Programming Languages  Machine Languages (0, 1)  Assembly Languages  More advanced than machine languages

5 5 Cont…  High Level Languages  Have English like syntax  Has an Interpreter or compiler.  Are divided into 2 categories:  Procedural (Conventional)  Object Oriented

6 6  Procedural Language: Problem is solved based on the tasks to be performed. A segment of code is written to accomplish each task. The segment of code is called a procedure / function. Ex: C

7 7 Object Oriented Languages:  Problem is solved based on the objects involved.  Objects have properties and methods (behavior).  Ex: C++

8 8 “C” Language:  Was introduced by “Dennis Ritchie” at Bell Labs in 1970 for writing the UNIX operating system.  Is a procedural language.  Uses available libraries to read, write, do math, use files, …  Can access bits of computer memory.  Can be executed on any platform.

9 9 Why C?  It is a small, high level, and structured language.  It can manipulate bits of computer memory.  Does not put high demand on memory.  Can run on different platforms with very little modification.

10 10 C Program’s Life Cycle:  Source file (.c) Object file (.obj)  Library files Executable file (.exe) Compiler Linker

11 11 What are C libraries?  Pre-compiled functions that come with the C compiler.  The functions are grouped in different packages called libraries.  To use functions included in a library, include the header file specified for that library in your program.  Ex: #include

12 12 Basic parts of a C program: // Display Hello World to screen: #include main() { printf(“Hello World!” ); }

13 13 What is preprocessor?  Is a program that processes the C program before it is compiled.  It looks for the lines that begin with # Preprocessor directive: Is any line that begins with #. ex: #include

14 14 Few things about the C Language: Is case sensitive. It must have a function main(). Program execution begins with function main(). The body of every function is surrounded in { } Every program statement ends with a ; Spaces are ignored in the code. Comments in C:  Comments are used for documentation and clarity of the code.  // single line comment….  /* multi-line comment ----------- ----------- */

15 15 Program Statements in C  Single statement: Is a combination of:  keywords,  Variables,  Literals: 334, “Hello”, 3.14  other tokens: ( ) ; int Ends with a ;  Compound statement: 2 or more C statements. Enclosed in {.. }.

16 16 Terminologies:  Token: Is a part of a statement that cannot be broken into smaller piece by the compiler, Ex: int, main, (, {, ;  Keyword: A word that has special meaning in the language. In C all keywords are in lower case. Ex: int, float, double, if, else, while, break, …

17 17 printf( ) function:  Is used to write to the standard output (screen).  Is included in one of the C libraries.  Include stdio.h header file in order to use this function. #include  Syntax: printf (“Whatever you wish to write!”);

18 18 Escape Character (\..):  Can be used inside the “...” of printf, to format the output: \n inserts a new line in the output \t inserts a tab \\ writes \ \” writes “ \’ writes ‘

19 19.  Ex: Write a C program to write the following to the screen: Your Name CIT105 This is my first C program ===================================

20 20 Types of data:  Numeric: Integer = whole numbers Floating point = real numbers  Non-numeric: Character: ‘a’ String: “anything between double quotes”

21 21 Data Types of numeric data:  Data types for whole Numbers: char 1 byte -128.. 127 short 2 Bytes -32,768.. 32,767 int 2 bytes long 4 bytes -2 billion.. 2 billion  Real numbers: float 4 bytes (7 digits after.) double 8 bytes (15 digits after.) The size/range of each data type depends on your computer.

22 22 Cont…  unsigned … The char, short, int, long have unsigned versions as well. unsigned char 1 byte 0.. 255  char data type: Takes one byte in memory. Can store small integers. Can store single characters: ‘g’  String data: There is no string data type in C. “abc” is a string literal / constant. Character arrays can be used to store string data in memory.

23 23 Next time:  What is a variable?  Working with variables,  Writing variables to the output  Arithmetic Operators in C


Download ppt "1 Key Concepts:  Why C?  Life Cycle Of a C program,  What is a computer program?  A program statement?  Basic parts of a C program,  Printf() function?"

Similar presentations


Ads by Google