Lecture 1 cis208 January 14 rd, 2005. Compiling %> gcc helloworld.c returns a.out %> gcc –o helloworld helloworld.c returns helloworld.

Slides:



Advertisements
Similar presentations
Introduction to C Systems Programming Concepts. Introduction to C A simple C Program A simple C Program –Variable Declarations –printf ( ) Compiling and.
Advertisements

11-2 Identify the parts of the “main” function, which include Preprocessor Directives main function header main function body which includes Declaration.
CS1061 C Programming Lecture 16: Formatted I/0 A. O’Riordan, 2004.
1 ICS103 Programming in C Lecture 3: Introduction to C (2)
Display a 12-Month Calendar CS-2301 D-term Programming Assignment #2 12-Month Calendar CS-2301 System Programming C-term 2009 (Slides include materials.
1 Lecture 2  Input-Process-Output  The Hello-world program  A Feet-to-inches program  Variables, expressions, assignments & initialization  printf()
More on Numerical Computation CS-2301 B-term More on Numerical Computation CS-2301, System Programming for Non-majors (Slides include materials from.
Introduction to C Programming Overview of C Hello World program Unix environment C programming basics.
Assignment #2, 12- month Calendar CS-2301, B-Term Programming Assignment #2 12-Month Calendar CS-2301, System Programming for Non-Majors (Slides.
Chapter 3: Introduction to C Programming Language C development environment A simple program example Characters and tokens Structure of a C program –comment.
The printf Method The printf method is another way to format output. It is based on the printf function of the C language. System.out.printf(,,,..., );
Lecture No: 16. The scanf() function In C programming language, the scanf() function is used to read information from standard input device (keyboard).
Computer Science 210 Computer Organization Introduction to C.
Ping Zhang 10/08/2010.  You can get data from the user (input) and display information to the user (output).  However, you must include the library.
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 9 Character Strings 9.1 Character String Constants A character string constant is a sequence of characters enclosed in double quotation mark. Examples.
History of C 1950 – FORTRAN (Formula Translator) 1959 – COBOL (Common Business Oriented Language) 1971 – Pascal Between Ada.
1 Programming in C Hello World! Soon I will control the world! Soon I will control the world!
Structure of a C program Preprocessor directive (header file) Program statement } Preprocessor directive Global variable declaration Comments Local variable.
Chapter 3: Formatted Input/Output Copyright © 2008 W. W. Norton & Company. All rights reserved. 1 Chapter 3 Formatted Input/Output.
PHYS 2020 Basic C An introduction to writing simple but useful programs in C In these lectures I will take you through the basics of C, but you will need.
Introduction to Programming
3. FORMATTED INPUT/OUTPUT. The printf Function The first argument in a call of printf is a string, which may contain both ordinary characters and conversion.
Lexical Elements, Operators, and the C Cystem. C overview recap functions –structured programming –return value is typed –arguments(parameters) pointers.
Introduction As programmers, we don’t want to have to implement functions for every possible task we encounter. The Standard C library contains functions.
Khalid Rasheed Shaikh Computer Programming Theory 1.
CSC141 Introduction to Computer Programming Teacher: AHMED MUMTAZ MUSTEHSAN Lecture - 6.
Minimal standard C program int main(void) { return 0 ; }
© Janice Regan, CMPT 102, Sept CMPT 102 Introduction to Scientific Computer Programming Input and Output.
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.
Dale Roberts Department of Computer and Information Science, School of Science, IUPUI Dale Roberts, Lecturer Computer Science, IUPUI
C is a high level language (HLL)
1 C Syntax and Semantics Dr. Sherif Mohamed Tawfik Lecture Two.
Chapter 3: Formatted Input/Output 1 Chapter 3 Formatted Input/Output.
+ Note On the Use of Different Data Types Use the data type that conserves memory and still accomplishes the desired purpose. For example, depending on.
Formatted I/O ä ä Standard Output ä ä printf() family of functions ä ä Standard Input ä ä scanf() family of functions.
Introduction to Computing Lecture 03: Basic input / output operations Introduction to Computing Lecture 03: Basic input / output operations Assist.Prof.Dr.
The Machine Model Memory
Computer Science 210 Computer Organization
A bit of C programming Lecture 3 Uli Raich.
ECE Application Programming
CS1010 Discussion Group 11 Week 4 – Overview of C programming.
Functions, Part 2 of 2 Topics Functions That Return a Value
ICS103 Programming in C Lecture 3: Introduction to C (2)
Getting Started with C.
C Short Overview Lembit Jürimägi.
Lecture2.
2008/11/10: Lecture 16 CMSC 104, Section 0101 John Y. Park
Programming in C Input / Output.
Input and Output Lecture 4.
Computer Science 210 Computer Organization
Formatted Input/Output
Lexical Elements, Operators, and the C Cystem
Programming in C Input / Output.
Lexical Elements, Operators, and the C Cystem
Functions, Part 2 of 3 Topics Functions That Return a Value
Programming Assignment #1 12-Month Calendar—
Programming in C Input / Output.
Formatted Input/Output
Conversion Check your class notes and given examples at class.
Formatted Input/Output
Introduction to C EECS May 2019.
Strings #include <stdio.h>
Introduction to C Programming
Functions, Part 2 of 3 Topics Functions That Return a Value
Introduction to C CSE 2031 Fall /15/2019 8:26 AM.
Functions, Part 2 of 3 Topics Functions That Return a Value
Presentation transcript:

Lecture 1 cis208 January 14 rd, 2005

Compiling %> gcc helloworld.c returns a.out %> gcc –o helloworld helloworld.c returns helloworld

Executing %> a.out %>./a.out %> helloworld %>./helloworld

The C Language Derived from B & BCPL Redefined as ANSI C American National Standards Institute

C / Java Differences Not Object Orientated Procedural implementation and design No Polymorphism Call-by-Value only No Virtual Machine Direct Memory Access and allocation Very Fast Easier to Optimize.

#include int main(void) { printf(“%s %s\n”, “Hello”,”World”); return 0; }

#include Adds other source files Similar to java’s import statements Implicit nesting - 8 Levels

#include continued Preprocessor command #include <> : standard libraries. #include “foo.h” “ “ : local h files. Give path.

Common Libraries stdio.h : standard I/O  printf, scanf, gets, puts, getch, etc stdlib.h : various functions  rand, abs, besearch, exit, etc string.h : string functions  strlen, memcpy, strcat, strchr, etc math.h : math functions  must compile with –lm option  trig functions,log, pow, sqrt

int main(void) int is return type. must have main function in gcc, arguments & returns not necessary if void.

Variable Declaration Must be at beginning No initialization == junk values. = is assignment operator variable = value; Correct value = variable; Wrong

declaration cont. int main(void) { char a, b=‘b’; int j = 5,i,k=8; int p;. }

basic types Page 110 char : characters. ‘a’, ‘b’, ‘1’, ‘2’, etc int : integers. 1, , -11, etc float : floating point decimals  1.11, 0.002, 1.231, etc double : same as float, but larger range

printf part of Formatted output to standard out  usually console  can be changed  advanced topic

printf int printf(const char *control_string, …, ); returns number of characters written to stdout

control_string (printf cont) Represents what will be printed. printf(“I like C \n”); \n is newline character printf(“I\nlike\nC\n”); I like C

printf cont… \ == escape character \n : newline \t : horizontal tab page 113

format specifiers % variable place holder in control string values plugged in during runtime printf(“%d\n%c %s\n”, 1,’a’,”nice”); 1-to-1 correspondence 1 a nice

format specifiers different types of input %c – character %d – decimal value %i - same as %d %f – float value %s – string Page 494

int main(void){ int i = 5, j = 2,k = 3; char a = ‘7’; printf(“%d + %d equals %c\n”,j,i,a); i = printf(“%d”,i+j+k); return 0; }

Minimum Field width numerical padding numerical values between % and specifier adds white spaces or zeros printf(“%05d%5d”,5,6); Mostly used to line up columns in console output

Precision Specifier sets number of significant digits float j = 5.0; printf(“%2.5f\n”,j); two white spaces and 7 digits after decimal point.