Minimal standard C program int main(void) { return 0 ; }

Slides:



Advertisements
Similar presentations
C++ Basics March 10th. A C++ program //if necessary include headers //#include void main() { //variable declaration //read values input from user //computation.
Advertisements

Programming In C++ Spring Semester 2013 Lecture 2 Programming In C++, Lecture 2.
C Programming Day 1 based upon Practical C Programming by Steve Oualline CS550 Operating Systems.
11-2 Identify the parts of the “main” function, which include Preprocessor Directives main function header main function body which includes Declaration.
Lecture 2 Introduction to C Programming
1 Chapter 2 Introduction to Java Applications Introduction Java application programming Display ____________________ Obtain information from the.
Introduction to C++ September 12, Today’s Agenda Quick Review Check your programs from yesterday Another Simple Program: Adding Two Numbers Rules.
Principles of Programming Fundamental of C Programming Language and Basic Input/Output Function 1.
1 ICS103 Programming in C Lecture 3: Introduction to C (2)
Structure of a C program
C Programming Language 4 Developed in 1972 by Dennis Ritchie at AT&T Bell Laboratories 4 Used to rewrite the UNIX operating system 4 Widely used on UNIX.
Unix Continuum of Tools Do something once: use the command line Do something many times: –Use an alias –Use a shell script Do something that is complex.
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?
1 Structured Programming in C Welcome to CPSC 206.
Chapter 3: Introduction to C Programming Language C development environment A simple program example Characters and tokens Structure of a C program –comment.
Introduction to C Language
By: Mr. Baha Hanene Chapter 3. Learning Outcomes We will cover the learning outcome 02 in this chapter i.e. Use basic data-types and input / output in.
Computer Science 210 Computer Organization Introduction to C.
C Programming Lecture 3. The Three Stages of Compiling a Program b The preprocessor is invoked The source code is modified b The compiler itself is invoked.
Chapter 2 : Overview of C By Suraya Alias. /*The classic HelloWorld */ #include int main(void) { printf(“Hello World!!"); return 0; }
Programming I Introduction Introduction The only way to learn a new programming language is by writing programs in it. The first program to.
C-Language Keywords(C99)
History of C 1950 – FORTRAN (Formula Translator) 1959 – COBOL (Common Business Oriented Language) 1971 – Pascal Between Ada.
EPSII 59:006 Spring Introduction to C More Administrative Details The C Programming Language How a computer processes programs Your first C program.
Week 1 Algorithmization and Programming Languages.
Constants Numeric Constants Integer Constants Floating Point Constants Character Constants Expressions Arithmetic Operators Assignment Operators Relational.
1 Programming in C Hello World! Soon I will control the world! Soon I will control the world!
Computer Programming I Hour 2 - Writing Your First C Program.
Structure of a C program Preprocessor directive (header file) Program statement } Preprocessor directive Global variable declaration Comments Local variable.
BASICS CONCEPTS OF ‘C’.  C Character Set C Character Set  Tokens in C Tokens in C  Constants Constants  Variables Variables  Global Variables Global.
THE BASICS OF A C++ PROGRAM EDP 4 / MATH 23 TTH 5:45 – 7:15.
Algorithms  Problem: Write pseudocode for a program that keeps asking the user to input integers until the user enters zero, and then determines and outputs.
Introduction to Programming
Lecture 1 cis208 January 14 rd, Compiling %> gcc helloworld.c returns a.out %> gcc –o helloworld helloworld.c returns helloworld.
DATA TYPE AND DISPLAY Computer Programming Asst. Prof. Dr. Choopan Rattanapoka and Asst. Prof. Dr. Suphot Chunwiphat.
A first program 1. #include 2. using namespace std; 3. int main() { 4. cout
Khalid Rasheed Shaikh Computer Programming Theory 1.
CSC141 Introduction to Computer Programming Teacher: AHMED MUMTAZ MUSTEHSAN Lecture - 6.
CSCI 3133 Programming with C Instructor: Bindra Shrestha University of Houston – Clear Lake.
1 Homework Done the reading? –K&R –Glass Chapters 1 and 2 Applied for cs240? (If not, keep at it!) Gotten a UNIX account? (If not, keep at it!)
CHAPTER 2 PROBLEM SOLVING USING C++ 1 C++ Programming PEG200/Saidatul Rahah.
Operating System Discussion Section. The Basics of C Reference: Lecture note 2 and 3 notes.html.
Program Development Cycle 1.Edit program 2.Compile program - translates it from C to machine language 3. Run/execute your program. 4. If not satisfied,
1 Lexical Elements, Operators, and the C System. 2 Outline Characters and Lexical Elements Syntax Rules Comments Keywords Identifiers Constants String.
Variables in C Topics  Naming Variables  Declaring Variables  Using Variables  The Assignment Statement Reading  Sections
Variables in C Topics  Naming Variables  Declaring Variables  Using Variables  The Assignment Statement Reading  Sections
CMSC 104, Version 8/061L09VariablesInC.ppt Variables in C Topics Naming Variables Declaring Variables Using Variables The Assignment Statement Reading.
An overview of C Language. Overview of C C language is a general purpose and structured programming language developed by 'Dennis Ritchie' at AT &T's.
C is a high level language (HLL)
Department of Electronic & Electrical Engineering Statements Blocks{} Semicolons ; Variables Names keywords Scope.
Sudeshna Sarkar, IIT Kharagpur 1 Programming and Data Structure Sudeshna Sarkar Lecture 3.
1 C Syntax and Semantics Dr. Sherif Mohamed Tawfik Lecture Two.
Chapter 1 slides1 What is C? A high-level language that is extremely useful for engineering computations. A computer language that has endured for almost.
Chapter 3 Using Variables, Constants, Formatting Mrs. UlshaferSept
Numbers in ‘C’ Two general categories: Integers Floats
CSCE 206 Structured Programming in C
Computer Science 210 Computer Organization
Chapter 1.2 Introduction to C++ Programming
Wel come.
ICS103 Programming in C Lecture 3: Introduction to C (2)
Introduction to C++.
Computer Science 210 Computer Organization
Variables In programming, we often need to have places to store data. These receptacles are called variables. They are called that because they can change.
Homework Applied for cs240? (If not, keep at it!) 8/10 Done with HW1?
WEEK-2.
The C Language: Intro.
Lexical Elements & Operators
Variables in C Topics Naming Variables Declaring Variables
Introduction to C Programming
Presentation transcript:

Minimal standard C program int main(void) { return 0 ; }

Function header int main(void) Return type – Integer according to ANSI C standard Return 0, for success Or better yet, return EXIT_SUCCESS Return non-zero, otherwise Name of function Argument types – void means no arguments – More later on (int argc, char *argv[])

C block Delimited by “curlies” – { } – Encloses C statements (more later) – Starts with variable declarations (more later) C90 and C++ are more forgiving – Can be nested Function code must be in a block

Minimal C program with I/O #include int main(void) { printf("Hello World\n") ; return 0 ; }

Standard libraries C has many “standard” libraries – But they really aren’t part of the “language” C preprocessor ( cpp ) – Processes lines starting with # And some other things #include – Adds ~900 lines of code needed to use standard I/O – cpp -E prog.c Shows what is added

Printing a line printf("3 feet is 36 inches\n") ; – Writes a line to standard output 3 built-in FILE ’s of C – Standard output ( stdout ) Normal terminal output – Standard error ( stderr ) Terminal output for errors – Standard input ( stdin ) Terminal input

Escape sequences Allows inclusion of special characters \n New line \t Horizontal tab \r Line feed \' Single quote \" Double quote \\ Backslash And a few more….

Formatted I/O Allows the pretty printing of variable data – Easy to get started – But it takes time to master Inspired by FORTRAN I/O – So it enables printing of aligned tables printf("Easy as %8.4f\n", PI) ; __ – Easy as __3.1416

Variables Names and places for data Global variables – Declared outside of blocks Local variables – Declared at beginning of blocks In K&R and ANSI C – Stored on the stack

Variable names Can contain – Letters (upper and lower) – Digits – Underscore Cannot start with a digit Cannot be a keyword – Like return

Variable declarations Type in C – Integer, floating point, character, … – Determines space needed for variable – Determines what kind of add to do Integer or IEEE floating? Declaration statements – int lengthInFeet ; – int x, y, Y, z ;

Assignment statements Gives a value to a variable – variable = expression ; For our example int feet, inches ; feet = 10 ; inches = 12*feet ;

The whole program #include int main(void) { int feet, inches ; feet = 5 ; inches = 12*feet ; printf("% d feet is %d inches\n", feet, inches) ; return 0 ; }

Things that go wrong Syntactic error – Your program isn’t in legal C inches = 12 feet ; Semantic error – Your program has a bug inches = feet/12 ;

Debuggers Programs to “step” through your code Linux gcc has gdb – Must compile with debugging symbols gcc -g …….. – Many features Set breakpoint Examine variables – Hard to master But worth the effort to learn a little

Phases Compiling – Preprocessor Expands #include statements – Lexical analysis Finds the tokens (or words) – Syntactic analysis Finds the expressions, statements, blocks, etc. – Code generation Linking – Adds in the library routines Loading – Processes DLL’s and relocation (if needed)