The detail of sea.c [1] #include <stdio.h> The preprocessor inserts the header file stdio.h at the point.

Size: px
Start display at page:

Download "The detail of sea.c [1] #include <stdio.h> The preprocessor inserts the header file stdio.h at the point."

Transcription

1 Chapter 1. An Overview 1.1 Programming and Preparation Operating systems : A collection of special programs Management of machine resources Text editor and C compiler C codes in text file. Source code to object code. (Source file: *.c) (Executable file: *.exe) ABC; 9/1/2004; Program Output An example of source sea.c printf( from sea to shining C\n ) ; Compile sea.c sea.c is preprocessed and then compiled The detail of sea.c [1] The preprocessor inserts the header file stdio.h at the point. Information about printf( ) function. The angle brackets < > The header file is in the usual place [2] : Definition of the function main( ) main( ) takes no arguments and returns an integer value. void int ( ) means main is a function void, int are keywords (32 keywords in C) [3] The braces indicate the start and the end of the function [4] printf( ) One of functions in the standard library It prints on the screen [5] from sea to shining C\n string (characters in double quotes) \n (backslash n) means newline Cursor to the beginning of the next line backslash n is treated as a single character

2 [6] printf( from sea to shining C\n ) The function is called or invoked and its argument is printed on the screen [7] printf( from sea to shining C\n ) ; A statement ends with a semicolon [8] return 0 ; : return statement It returns 0 to the operating system, which may be used later. ABC; 9/1/2004; 1-2 Three examples with printf( ) printf("from sea to shining C\n") ; return 0 ; /* printf("from sea to ") ; printf("shining C") ; printf("\n") ; printf("from sea\n") ; printf("to shining\nc\n") ; */ printf("\n\n\n\n\n\n\n\n\n\n"); printf(" ***********************\n"); printf(" * from sea *\n"); printf(" * to shining C *\n"); printf(" ***********************\n"); printf("\n\n\n\n\n\n\n\n\n\n"); 1.3 Variables, Expressions, and Assignment Numbers in mathematics : natural numbers, integers, real numbers, imaginary numbers Numbers without imaginary parts Natural numbers, negatives of these and zero Two types of numbers in C integers, floating-point numbers decimal point Three floating types : float : 6 significant digits after the decimal point double : 15 digits long double : At leat as many digits as a double. In C floating numbers are automatically of type double. Variables can store integers and floating numbers. Variables must be declared at the beginning of the program. A variable name is called an identifier. Letters, digits, and underscore (But no digits at the beginning)

3 ABC; 9/1/2004; 1-3 Assignment statement x = 7.0 ; y = x + 3 ; assignment operator Expression The right side of the assignment operator, or the arguemnt to a function. THE EVALUATION OF EXPRESSIONS INVOLVES CONVERSIONS. y = 7 / 2 ; y = 3 division of two integers y = 7.0 / 2 ; y = is converted to a double division of a double by an integer Example: Convert the marathon distance (26 miles and 385 yards) to kilometers. Km/Mi = 1.609, Yd/Mi = /* The distance of a marathon in kilometers. */ A comment int miles, yards ; /* Declaration */ float kilometers ; /* kilometers is of type float */ miles = 26 ; /* Assignment statement */ yards = 385 ; kilometers = * (miles + yards / ) ; /* Assignment statement */ /* multiplication, addition, division */ /* ( ) is calculated first. * and / precede + and - */ printf( \na marathon is %f kilometers. \n\n, kilometers) ; Control string Format Variable (It prints the variable kilometers as a floating-point number) return 0 ;

4 1.4 The Use of #define and #include A line beginning with # : preprocessing directive. Normally, they are at the beginning of the program. ABC; 9/1/2004; 1-4 #define PI All the PI s after the line are converted to , except in strings, printf( PI = %f\n, PI) ; Advantage of using #define The program becomes more readable. It is easy to change its value later. #include my_file.h my_file.h is inserted at this point of the program. The difference between #include... and #include <...> Example: pacific_sea.c in page 15 [1] These are exactly the same. #define SQ_FEET_PER_SQ_MILE (5280*5280) #define SQ_FEET_PER_SQ_MILE 5280*5280 #define SQ_FEET_PER_SQ_MILE [2] #define AREA 2337 const int pacific_sea = AREA ; type qualifier (pacific-sea can be initialized but not changed thereafter) 2337 AREA pacific_sea preprocessor compiler [3] printf( %22.7e acres\n, acres) ; e+05 acres e-format scientific notation, X : total spaces 7 : number of digits after the decimal point

5 1.5 The Use of printf( ) and scanf( ) printf( ) is used for output scanf( ) is used for input : f stands for formatted ABC; 9/1/2004; 1-5 printf(control string, arguments) variable, string, character, etc. Examples: printf( abc ) ; It contains conversion specifications (% + field width + conversion character) number of spaces for printing printf( %s, abc ) ; printf( %c%c%c, a, b, c ) ; : s = string : c = character printf( %c%3c%5c, A, B, C ) ; A B C Conversion characters : scanf(control string, addresses) scanf( %d, &x) ; : & = address operator Read characters as an integer and store it at x. scanf() returns the number of conversions Example: Type 1337 on the keyboard A decimal integer %d Not an integer but a string

6 scanf() skips spaces in reading numbers but not in reading a character. ABC; 9/1/2004; 1-6 char c1, c2, c3; int i; float x; double y; printf("\n%s\n%s", "Input three characters", "an int, a float, and a double: "); scanf("%c%c%c%d%f%lf", &c1, &c2, &c3, &i, &x, &y); printf("\nhere is the data that you typed in:\n"); printf("%3c%3c%3c%5d%17e%17e\n\n", c1, c2, c3, i, x, y); Try to type Conversion characters : 1.6 Flow of Control Statements are normally executed in sequence, from top to bottom. if and if-else statements : Used for alternative actions while and for statements : Used for looping These require the evaluation of logical expressions (true or false) zero value non-zero value if (expr) If expr is true, then statement is executed. Statement If expr is false, then statement is skipped. a = 1 ; if (b == 3) a = 5 ; /* single statement */ is-equal-to operator printf( %d, a) ;

7 A compound statement is surrounded by braces if ( b == 3 ) b = 5 ; c = 7 ; ABC; 9/1/2004; 1-7 if (expr) If expr is true (nonzero), statement1 is executed. statement1 Otherwise, statement2 is executed. else statement2 if(cnt == 0) a = 2; b = 3; c = 5; else a = -1; b = -2; c = -3; while (expr) If expr is true, the statement is executed. statement The while loop is executed again until expr is false. int i = 1, sum = 0 ; while (i <= 5) /* <= is less-than-or-equal-to operator */ sum += i ; /* sum = sum + i */ ++ i ; /* i = i + 1 */ printf( sum = %d\n, sum) ; return 0 ; for (expr1; expr2; expr3) expr1 : An initial assignment statement expr2 : A test expr3 : An increment at the end of the statement It is the same as the following: expr1 while (expr2) statement expr3 for ( i = 1; i <= 5; ++i) sum += i ;

8 Example : running_sum.c /* Compute the minimum, maximum, sum, and average. */ ABC; 9/1/2004; 1-8 #include <stdlib.h> int i; double x, min, max, sum, avg; if (scanf("%lf", &x)!= 1) // scanf() returns no. of conversions. // not-equal-to operator printf("no data found - bye!\n"); exit(1); // 0 for normal exit, 1 for otherwise min = max = sum = avg = x; printf("%5s%9s%9s%9s%12s%12s\n%5s%9s%9s%9s%12s%12s\n\n", // print headings "Count", "Item", "Min", "Max", "Sum", "Average",,,,,, ) ; printf("%5d%9.1f%9.1f%9.1f%12.3f%12.3f\n", 1, x, min, max, sum, avg); // print the first line for (i = 2; scanf("%lf", &x) == 1; ++i) // repeat until the test is false if (x < min) // i is incremented at the end min = x; else if (x > max) max = x; sum += x; avg = sum / i; printf("%5d%9.1f%9.1f%9.1f%12.3f%12.3f\n", i, x, min, max, sum, avg); 1.7 Functions A function is a piece of code. A function should be declared before used function declaration or function prototype. They are in the header files. The general form of function prototype type function_name( pararmeter type list ) ; void if no value is returned. void if no argument is taken. Example: The power function pow(2.0, 3.0) The function prototype: double pow(double x, double y) ; // x, y are not used by the compiler. // They are optional.

9 ABC; 9/1/2004; 1-9 Example: maxmin.c // Function prototypes at the top after #include and #define float maximum(float x, float y); float minimum(float x, float y); void prn_info(void); // prn_info takes no arguments and returns no values int i, n; float max, min, x; // Variable declaration prn_info(); // Function call printf("input n: "); scanf("%d", &n); printf("\ninput %d real numbers: ", n); scanf("%f", &x); max = min = x; // max = (min = x) ; for (i = 2; i <= n; ++i) scanf("%f", &x); max = maximum(max, x); // Arguments are always passed by value. min = minimum(min, x); // The copy of the value of max is passed. // No change in max by the function call printf("\n%s%11.3f\n%s%11.3f\n\n, "Maximum value:", max, Minimum value:", min); float maximum(float x, float y) if (x > y) return x; else return y; // Function definition // Identifier x is unrelated to x in the main float minimum(float x, float y) // Header // Body if (x < y) return x; else return y; void prn_info(void) printf("\n%s\n%s\n\n", "This program reads an integer value for n, and then", "processes n real numbers to find max and min values.");

10 Call-by-value Arguments to a function are always passed by value. The variables in the argument are not changed by calling the function. ABC; 9/1/2004; 1-10 Example int a = 1; void try_to_change_it(int); /* function prototype */ printf("%d\n", a); /* 1 is printed */ try_to_change_it(a); /* function call */ printf("%d\n", a); /* 1 is printed again! */ void try_to_change_it(int a) a = 777; Call-by-reference The variables in the argument can be changed by calling the function. (Pointers should be used) 1.8 Arrays, Strings, and Pointers A string is an array of characters. abc123 a A pointer is an address in C An array name is treated as a pointer Arrays An array contains many variables of the same type int a[3] ; Three integer constants a[0], a[1], a[2]. The index starts from zero.

11 Example : scores.c #define CLASS_SIZE 5 ABC; 9/1/2004; 1-11 int i, j, score[class_size], sum = 0, tmp; printf("input %d scores: ", CLASS_SIZE); for (i = 0; i < CLASS_SIZE; ++i) scanf("%d", &score[i]); sum += score[i]; for (i = 0; i < CLASS_SIZE - 1; ++i) /* bubble sort */ for (j = CLASS_SIZE - 1; j > i; --j) if (score[j-1] < score[j]) /* check the order */ tmp = score[j-1]; score[j-1] = score[j]; score[j] = tmp; printf("\nordered scores:\n\n"); for (i = 0; i < CLASS_SIZE; ++i) printf(" score[%d] =%5d\n", i, score[i]); printf("\n%18d%s\n%18.1f%s\n\n", sum, " is the sum of all the scores", (double) sum / CLASS_SIZE, " is the class average"); /* cast operator. Interger value of sum is converted to a double. sum / CLASS_SIZE The fraction is ignored. */ Strings A string is an array of characters. a b_3 The end of a string should be \0 null character A character has an interger value of ASCII coding ( a = 97, b = 98,...)

12 Example: /* Have a nice day! */ ABC; 9/1/2004; 1-12 #include <ctype.h> // For isalpha(), is a character alphabetic? /* For getchar(), putchar(), printf() Write characters on the screen Read characters from the keyborad */ #define MAXSTRING 100 char c, name[maxstring]; // 99 characters + \0 in name. int i, sum = 0; // sum is initialized to zero printf("\nhi! What is your name? "); for (i = 0; (c = getchar())!= '\n'; ++i) read a character from the keyboard and assign it to c name[i] = c; if (isalpha(c)) // Is c one of alphabets? sum += c; // A character as a ASCII value name[i] = '\0'; /* Strings should end with a null character printf("\n%s%s%s\n%s","nice to meet you ", name, ".", "Your name spelled backwards is "); To print the array name // i = 15 at this point. Print the name backwards on the screen for (--i; i >= 0; --i) putchar(name[i]); printf("\n%s%d%s\n\n%s\n", "and the letters in your name sum to ", sum, ".", "Have a nice day!"); */ Pointers A pointer is an address of an object in memory. char c = a, *p ; p is of type pointer to char. c is of type char and initialized to a. p = &c ; address operator The address of c is stored in p (p is pointing to c) printf( %c%c%c, c, *p, *P + 1) ; indirection operator. *p+1 is one more than the value of *p. The value of what p is pointing to

13 Example: abc.c #include <string.h> #define MAXSTRING 100 char c = a, *p, s[maxstring] ; p = &c ; // For strcpy() to copy a string ABC; 9/1/2004; 1-13 // The string s has size MAXSTRING. printf( %c%c%c, *p, *p + 1, *p + 2) ; strcpy(s, ABC ) ; // ABC is copied to s printf( %s %c%c%s\n, s, *s + 6, *s + 7, s +1) ; // s is a pointer pointing to s[0]. *s = s[0] = A. *s + 6 = G // s+1 = address of s[1]. *(s+1 )= s[1] = B strcpy(s, she sells sea shells by the seashore ) ; p = s + 14 ; // p is a pointer variable, s is a pointer constant. s = p ; ERROR // p = &s[14]. for ( ; *p!= \0 ; ++p) if (*p == e ) *p = E ; if (*p == ) *p = \n ; printf( %s\n, s) ; return 0 ; 1.9 Files To open a file my_file // Need for fopen()... FILE *ifp ; // pointer to FILE ifp = fopen( my_file, r ) ; file name mode, r for read... w for write. Create the file or start writing from the beginning of the file. a for append. Write just after the last writing. Simultaneous opening of files = 20 or 64. fopen() returns NULL if not successful. fclose() closes the opened files. The C system closes all opened files at the end. Argument to main() int main(int argc, char *argv[]) Argument vector. Argument count. (The array points to successive words in the command line) (Number of arguments in the command line) Command line: cnt_letters chapter1 data1 argv[0] points to cnt_letters, argv[1] points to chapter1, argv[2] points to data1

14 Example: cnt_letters.c /* Count uppercase letters in a file */ ABC; 9/1/2004; 1-14 #include <stdlib. h> int main(int argc, char *argv[]) int c, i, letter[26]; FILE *ifp, *ofp; /* infile pointer, outfile pointer. */ if(argc!= 3) /* An error if not three arguments. */ printf( \n%s%s%s\n\n%s\n%s\n\n, Usage:, argv[0], infile outfile, The uppercase letters in infile will be counted., The results will be written in outfile. ) exit(1); ifp = fopen(argv[1], r ); ofp = fopen(argv[2], w ); for (i =0; i < 26; ++i) /* The array is automatically initialized */ letter[i] = 0; /* Manual initialization to be sure. */ while ((c = getc(ifp))!= EOF) /* EOF = end-of-file. #define EOF (-1) */ Read a character from the file. It returns EOF at the end of the file. if (c >= A && c <= Z ) /* Find uppercase letters */ Logical AND operator ++letter[c - A ]; /* If c = D, letter[3] is incremented */ for (i = 0; i < 26; ++i) if(i % 6 == 0) /* Remainder of i/6 */ MODULUS operator putc( \n, ofp); /* Write a character in the file. fprintf(ofp, %c:%5d putc( \n, ofp); Print \n for every sixth time */, A + i, letter[i]); /* Formatted print in a file */ fclose(ifp) ; /* Close file explicitly, optional */ fclose(ofp) ; Command line: cnt_letters chapter1 data1

C Overview Fall 2015 Jinkyu Jeong

C Overview Fall 2015 Jinkyu Jeong C Overview Fall 2015 Jinkyu Jeong (jinkyu@skku.edu) 1 # for preprocessor Indicates where to look for printf() function.h file is a header file #include int main(void) printf("hello, world!\n");

More information

C Overview Fall 2014 Jinkyu Jeong

C Overview Fall 2014 Jinkyu Jeong C Overview Fall 2014 Jinkyu Jeong (jinkyu@skku.edu) 1 # for preprocessor Indicates where to look for printf() function.h file is a header file #include int main(void) { printf("hello, world!\n");

More information

AN OVERVIEW OF C, PART 3. CSE 130: Introduction to Programming in C Stony Brook University

AN OVERVIEW OF C, PART 3. CSE 130: Introduction to Programming in C Stony Brook University AN OVERVIEW OF C, PART 3 CSE 130: Introduction to Programming in C Stony Brook University FANCIER OUTPUT FORMATTING Recall that you can insert a text field width value into a printf() format specifier:

More information

Fundamental of Programming (C)

Fundamental of Programming (C) Borrowed from lecturer notes by Omid Jafarinezhad Fundamental of Programming (C) Lecturer: Vahid Khodabakhshi Lecture 3 Constants, Variables, Data Types, And Operations Department of Computer Engineering

More information

Features of C. Portable Procedural / Modular Structured Language Statically typed Middle level language

Features of C. Portable Procedural / Modular Structured Language Statically typed Middle level language 1 History C is a general-purpose, high-level language that was originally developed by Dennis M. Ritchie to develop the UNIX operating system at Bell Labs. C was originally first implemented on the DEC

More information

B.V. Patel Institute of Business Management, Computer & Information Technology, Uka Tarsadia University

B.V. Patel Institute of Business Management, Computer & Information Technology, Uka Tarsadia University Unit 1 Programming Language and Overview of C 1. State whether the following statements are true or false. a. Every line in a C program should end with a semicolon. b. In C language lowercase letters are

More information

Fundamentals of Programming Session 4

Fundamentals of Programming Session 4 Fundamentals of Programming Session 4 Instructor: Reza Entezari-Maleki Email: entezari@ce.sharif.edu 1 Fall 2011 These slides are created using Deitel s slides, ( 1992-2010 by Pearson Education, Inc).

More information

C: How to Program. Week /Mar/05

C: How to Program. Week /Mar/05 1 C: How to Program Week 2 2007/Mar/05 Chapter 2 - Introduction to C Programming 2 Outline 2.1 Introduction 2.2 A Simple C Program: Printing a Line of Text 2.3 Another Simple C Program: Adding Two Integers

More information

Programming for Engineers Introduction to C

Programming for Engineers Introduction to C Programming for Engineers Introduction to C ICEN 200 Spring 2018 Prof. Dola Saha 1 Simple Program 2 Comments // Fig. 2.1: fig02_01.c // A first program in C begin with //, indicating that these two lines

More information

Fundamentals of Programming. Lecture 3: Introduction to C Programming

Fundamentals of Programming. Lecture 3: Introduction to C Programming Fundamentals of Programming Lecture 3: Introduction to C Programming Instructor: Fatemeh Zamani f_zamani@ce.sharif.edu Sharif University of Technology Computer Engineering Department Outline A Simple C

More information

Chapter 2 - Introduction to C Programming

Chapter 2 - Introduction to C Programming Chapter 2 - Introduction to C Programming 2 Outline 2.1 Introduction 2.2 A Simple C Program: Printing a Line of Text 2.3 Another Simple C Program: Adding Two Integers 2.4 Memory Concepts 2.5 Arithmetic

More information

C Program. Output. Hi everyone. #include <stdio.h> main () { printf ( Hi everyone\n ); }

C Program. Output. Hi everyone. #include <stdio.h> main () { printf ( Hi everyone\n ); } C Program Output #include main () { printf ( Hi everyone\n ); Hi everyone #include main () { printf ( Hi everyone\n ); #include and main are Keywords (or Reserved Words) Reserved Words

More information

Programming and Data Structures

Programming and Data Structures Programming and Data Structures Teacher: Sudeshna Sarkar sudeshna@cse.iitkgp.ernet.in Department of Computer Science and Engineering Indian Institute of Technology Kharagpur #include int main()

More information

These are reserved words of the C language. For example int, float, if, else, for, while etc.

These are reserved words of the C language. For example int, float, if, else, for, while etc. Tokens in C Keywords These are reserved words of the C language. For example int, float, if, else, for, while etc. Identifiers An Identifier is a sequence of letters and digits, but must start with a letter.

More information

Overview of C, Part 2. CSE 130: Introduction to Programming in C Stony Brook University

Overview of C, Part 2. CSE 130: Introduction to Programming in C Stony Brook University Overview of C, Part 2 CSE 130: Introduction to Programming in C Stony Brook University Integer Arithmetic in C Addition, subtraction, and multiplication work as you would expect Division (/) returns the

More information

Fundamental Data Types. CSE 130: Introduction to Programming in C Stony Brook University

Fundamental Data Types. CSE 130: Introduction to Programming in C Stony Brook University Fundamental Data Types CSE 130: Introduction to Programming in C Stony Brook University Program Organization in C The C System C consists of several parts: The C language The preprocessor The compiler

More information

Computer System and programming in C

Computer System and programming in C 1 Basic Data Types Integral Types Integers are stored in various sizes. They can be signed or unsigned. Example Suppose an integer is represented by a byte (8 bits). Leftmost bit is sign bit. If the sign

More information

File IO and command line input CSE 2451

File IO and command line input CSE 2451 File IO and command line input CSE 2451 File functions Open/Close files fopen() open a stream for a file fclose() closes a stream One character at a time: fgetc() similar to getchar() fputc() similar to

More information

C How to Program, 6/e by Pearson Education, Inc. All Rights Reserved.

C How to Program, 6/e by Pearson Education, Inc. All Rights Reserved. C How to Program, 6/e 1992-2010 by Pearson Education, Inc. An important part of the solution to any problem is the presentation of the results. In this chapter, we discuss in depth the formatting features

More information

Fundamentals of Programming

Fundamentals of Programming Fundamentals of Programming Lecture 3 - Constants, Variables, Data Types, And Operations Lecturer : Ebrahim Jahandar Borrowed from lecturer notes by Omid Jafarinezhad Outline C Program Data types Variables

More information

LESSON 4. The DATA TYPE char

LESSON 4. The DATA TYPE char LESSON 4 This lesson introduces some of the basic ideas involved in character processing. The lesson discusses how characters are stored and manipulated by the C language, how characters can be treated

More information

Main Program. C Programming Notes. #include <stdio.h> main() { printf( Hello ); } Comments: /* comment */ //comment. Dr. Karne Towson University

Main Program. C Programming Notes. #include <stdio.h> main() { printf( Hello ); } Comments: /* comment */ //comment. Dr. Karne Towson University C Programming Notes Dr. Karne Towson University Reference for C http://www.cplusplus.com/reference/ Main Program #include main() printf( Hello ); Comments: /* comment */ //comment 1 Data Types

More information

Multiple Choice Questions ( 1 mark)

Multiple Choice Questions ( 1 mark) Multiple Choice Questions ( 1 mark) Unit-1 1. is a step by step approach to solve any problem.. a) Process b) Programming Language c) Algorithm d) Compiler 2. The process of walking through a program s

More information

Introduction to C Programming. Chih-Wei Tang ( 唐之瑋 ) Department of Communication Engineering National Central University JhongLi, Taiwan

Introduction to C Programming. Chih-Wei Tang ( 唐之瑋 ) Department of Communication Engineering National Central University JhongLi, Taiwan Introduction to C Programming Chih-Wei Tang ( 唐之瑋 ) Department of Communication Engineering National Central University JhongLi, Taiwan Outline Printing texts Adding 2 integers Comparing 2 integers C.E.,

More information

2/29/2016. Definition: Computer Program. A simple model of the computer. Example: Computer Program. Data types, variables, constants

2/29/2016. Definition: Computer Program. A simple model of the computer. Example: Computer Program. Data types, variables, constants Data types, variables, constants Outline.1 Introduction. Text.3 Memory Concepts.4 Naming Convention of Variables.5 Arithmetic in C.6 Type Conversion Definition: Computer Program A Computer program is a

More information

Approximately a Test II CPSC 206

Approximately a Test II CPSC 206 Approximately a Test II CPSC 206 Sometime in history based on Kelly and Pohl Last name, First Name Last 5 digits of ID Write your section number(s): All parts of this exam are required unless plainly and

More information

8. Characters, Strings and Files

8. Characters, Strings and Files REGZ9280: Global Education Short Course - Engineering 8. Characters, Strings and Files Reading: Moffat, Chapter 7, 11 REGZ9280 14s2 8. Characters and Arrays 1 ASCII The ASCII table gives a correspondence

More information

BİL200 TUTORIAL-EXERCISES Objective:

BİL200 TUTORIAL-EXERCISES Objective: Objective: The purpose of this tutorial is learning the usage of -preprocessors -header files -printf(), scanf(), gets() functions -logic operators and conditional cases A preprocessor is a program that

More information

UNIT- 3 Introduction to C++

UNIT- 3 Introduction to C++ UNIT- 3 Introduction to C++ C++ Character Sets: Letters A-Z, a-z Digits 0-9 Special Symbols Space + - * / ^ \ ( ) [ ] =!= . $, ; : %! &? _ # = @ White Spaces Blank spaces, horizontal tab, carriage

More information

Work relative to other classes

Work relative to other classes Work relative to other classes 1 Hours/week on projects 2 C BOOTCAMP DAY 1 CS3600, Northeastern University Slides adapted from Anandha Gopalan s CS132 course at Univ. of Pittsburgh Overview C: A language

More information

C Language Part 1 Digital Computer Concept and Practice Copyright 2012 by Jaejin Lee

C Language Part 1 Digital Computer Concept and Practice Copyright 2012 by Jaejin Lee C Language Part 1 (Minor modifications by the instructor) References C for Python Programmers, by Carl Burch, 2011. http://www.toves.org/books/cpy/ The C Programming Language. 2nd ed., Kernighan, Brian,

More information

CSE 230 Intermediate Programming in C and C++ Input/Output and Operating System

CSE 230 Intermediate Programming in C and C++ Input/Output and Operating System CSE 230 Intermediate Programming in C and C++ Input/Output and Operating System Fall 2017 Stony Brook University Instructor: Shebuti Rayana shebuti.rayana@stonybrook.edu Outline Use of some input/output

More information

ANSI C Programming Simple Programs

ANSI C Programming Simple Programs ANSI C Programming Simple Programs /* This program computes the distance between two points */ #include #include #include main() { /* Declare and initialize variables */ double

More information

Copyright The McGraw-Hill Companies, Inc. Permission required for reproduction or display.

Copyright The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter 18 I/O in C Standard C Library I/O commands are not included as part of the C language. Instead, they are part of the Standard C Library. A collection of functions and macros that must be implemented

More information

Arrays, Strings, & Pointers

Arrays, Strings, & Pointers Arrays, Strings, & Pointers Alexander Nelson August 31, 2018 University of Arkansas - Department of Computer Science and Computer Engineering Arrays, Strings, & Pointers Arrays, Strings, & Pointers are

More information

Basic Elements of C. Staff Incharge: S.Sasirekha

Basic Elements of C. Staff Incharge: S.Sasirekha Basic Elements of C Staff Incharge: S.Sasirekha Basic Elements of C Character Set Identifiers & Keywords Constants Variables Data Types Declaration Expressions & Statements C Character Set Letters Uppercase

More information

Fundamentals of Programming

Fundamentals of Programming Fundamentals of Programming Lecture 4 Input & Output Lecturer : Ebrahim Jahandar Borrowed from lecturer notes by Omid Jafarinezhad Outline printf scanf putchar getchar getch getche Input and Output in

More information

Fundamental of Programming (C)

Fundamental of Programming (C) Borrowed from lecturer notes by Omid Jafarinezhad Fundamental of Programming (C) Lecturer: Vahid Khodabakhshi CE 43 - Fall 97 Lecture 4 Input and Output Department of Computer Engineering Outline printf

More information

Input/Output: Advanced Concepts

Input/Output: Advanced Concepts Input/Output: Advanced Concepts CSE 130: Introduction to Programming in C Stony Brook University Related reading: Kelley/Pohl 1.9, 11.1 11.7 Output Formatting Review Recall that printf() employs a control

More information

Data types, variables, constants

Data types, variables, constants Data types, variables, constants Outline 2.1 Introduction 2.2 A Simple C Program: Printing a Line of Text 2.3 Another Simple C Program: Adding Two Integers 2.4 Memory Concepts 2.5 Arithmetic in C 2.6 Decision

More information

THE FUNDAMENTAL DATA TYPES

THE FUNDAMENTAL DATA TYPES THE FUNDAMENTAL DATA TYPES Declarations, Expressions, and Assignments Variables and constants are the objects that a prog. manipulates. All variables must be declared before they can be used. #include

More information

UNIT - I. Introduction to C Programming. BY A. Vijay Bharath

UNIT - I. Introduction to C Programming. BY A. Vijay Bharath UNIT - I Introduction to C Programming Introduction to C C was originally developed in the year 1970s by Dennis Ritchie at Bell Laboratories, Inc. C is a general-purpose programming language. It has been

More information

are all acceptable. With the right compiler flags, Java/C++ style comments are also acceptable.

are all acceptable. With the right compiler flags, Java/C++ style comments are also acceptable. CMPS 12M Introduction to Data Structures Lab Lab Assignment 3 The purpose of this lab assignment is to introduce the C programming language, including standard input-output functions, command line arguments,

More information

CS102: Variables and Expressions

CS102: Variables and Expressions CS102: Variables and Expressions The topic of variables is one of the most important in C or any other high-level programming language. We will start with a simple example: int x; printf("the value of

More information

Chapter 1 & 2 Introduction to C Language

Chapter 1 & 2 Introduction to C Language 1 Chapter 1 & 2 Introduction to C Language Copyright 2007 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 1 & 2 - Introduction to C Language 2 Outline 1.1 The History

More information

Course organization. Course introduction ( Week 1)

Course organization. Course introduction ( Week 1) Course organization Course introduction ( Week 1) Code editor: Emacs Part I: Introduction to C programming language (Week 2-9) Chapter 1: Overall Introduction (Week 1-3) Chapter 2: Types, operators and

More information

Course Outline Introduction to C-Programming

Course Outline Introduction to C-Programming ECE3411 Fall 2015 Lecture 1a. Course Outline Introduction to C-Programming Marten van Dijk, Syed Kamran Haider Department of Electrical & Computer Engineering University of Connecticut Email: {vandijk,

More information

Applied Programming and Computer Science, DD2325/appcs15 PODF, Programmering och datalogi för fysiker, DA7011

Applied Programming and Computer Science, DD2325/appcs15 PODF, Programmering och datalogi för fysiker, DA7011 Applied Programming and Computer Science, DD2325/appcs15 PODF, Programmering och datalogi för fysiker, DA7011 Autumn 2015 Lecture 3, Simple C programming M. Eriksson (with contributions from A. Maki and

More information

ET156 Introduction to C Programming

ET156 Introduction to C Programming ET156 Introduction to C Programming g Unit 22 C Language Elements, Input/output functions, ARITHMETIC EXPRESSIONS AND LIBRARY FUNCTIONS Instructor : Stan Kong Email : skong@itt tech.edutech.edu General

More information

Objectives. Chapter 2: Basic Elements of C++ Introduction. Objectives (cont d.) A C++ Program (cont d.) A C++ Program

Objectives. Chapter 2: Basic Elements of C++ Introduction. Objectives (cont d.) A C++ Program (cont d.) A C++ Program Objectives Chapter 2: Basic Elements of C++ In this chapter, you will: Become familiar with functions, special symbols, and identifiers in C++ Explore simple data types Discover how a program evaluates

More information

Simple Java Reference

Simple Java Reference Simple Java Reference This document provides a reference to all the Java syntax used in the Computational Methods course. 1 Compiling and running... 2 2 The main() method... 3 3 Primitive variable types...

More information

Chapter 2: Basic Elements of C++ Objectives. Objectives (cont d.) A C++ Program. Introduction

Chapter 2: Basic Elements of C++ Objectives. Objectives (cont d.) A C++ Program. Introduction Chapter 2: Basic Elements of C++ C++ Programming: From Problem Analysis to Program Design, Fifth Edition 1 Objectives In this chapter, you will: Become familiar with functions, special symbols, and identifiers

More information

ITC213: STRUCTURED PROGRAMMING. Bhaskar Shrestha National College of Computer Studies Tribhuvan University

ITC213: STRUCTURED PROGRAMMING. Bhaskar Shrestha National College of Computer Studies Tribhuvan University ITC213: STRUCTURED PROGRAMMING Bhaskar Shrestha National College of Computer Studies Tribhuvan University Lecture 07: Data Input and Output Readings: Chapter 4 Input /Output Operations A program needs

More information

IECD Institute for Entrepreneurship and Career Development Bharathidasan University, Tiruchirappalli 23.

IECD Institute for Entrepreneurship and Career Development Bharathidasan University, Tiruchirappalli 23. Subject code - CCP01 Chapt Chapter 1 INTRODUCTION TO C 1. A group of software developed for certain purpose are referred as ---- a. Program b. Variable c. Software d. Data 2. Software is classified into

More information

today cs3157-fall2002-sklar-lect05 1

today cs3157-fall2002-sklar-lect05 1 today homework #1 due on monday sep 23, 6am some miscellaneous topics: logical operators random numbers character handling functions FILE I/O strings arrays pointers cs3157-fall2002-sklar-lect05 1 logical

More information

printf( Please enter another number: ); scanf( %d, &num2);

printf( Please enter another number: ); scanf( %d, &num2); CIT 593 Intro to Computer Systems Lecture #13 (11/1/12) Now that we've looked at how an assembly language program runs on a computer, we're ready to move up a level and start working with more powerful

More information

Programming and Data Structure

Programming and Data Structure Programming and Data Structure Sujoy Ghose Sudeshna Sarkar Jayanta Mukhopadhyay Dept. of Computer Science & Engineering. Indian Institute of Technology Kharagpur Spring Semester 2012 Programming and Data

More information

A Fast Review of C Essentials Part I

A Fast Review of C Essentials Part I A Fast Review of C Essentials Part I Structural Programming by Z. Cihan TAYSI Outline Program development C Essentials Functions Variables & constants Names Formatting Comments Preprocessor Data types

More information

Fundamentals of Programming. Lecture 11: C Characters and Strings

Fundamentals of Programming. Lecture 11: C Characters and Strings 1 Fundamentals of Programming Lecture 11: C Characters and Strings Instructor: Fatemeh Zamani f_zamani@ce.sharif.edu Sharif University of Technology Computer Engineering Department The lectures of this

More information

Chapter 8 - Characters and Strings

Chapter 8 - Characters and Strings 1 Chapter 8 - Characters and Strings Outline 8.1 Introduction 8.2 Fundamentals of Strings and Characters 8.3 Character Handling Library 8.4 String Conversion Functions 8.5 Standard Input/Output Library

More information

Contents. A Review of C language. Visual C Visual C++ 6.0

Contents. A Review of C language. Visual C Visual C++ 6.0 A Review of C language C++ Object Oriented Programming Pei-yih Ting NTOU CS Modified from www.cse.cuhk.edu.hk/~csc2520/tuto/csc2520_tuto01.ppt 1 2 3 4 5 6 7 8 9 10 Double click 11 12 Compile a single source

More information

Basic C Programming (2) Bin Li Assistant Professor Dept. of Electrical, Computer and Biomedical Engineering University of Rhode Island

Basic C Programming (2) Bin Li Assistant Professor Dept. of Electrical, Computer and Biomedical Engineering University of Rhode Island Basic C Programming (2) Bin Li Assistant Professor Dept. of Electrical, Computer and Biomedical Engineering University of Rhode Island Data Types Basic Types Enumerated types The type void Derived types

More information

10/6/2015. C Input/Output. stdin, stdout, stderr. C Language II. CMSC 313 Sections 01, 02. C opens three input/output devices automatically:

10/6/2015. C Input/Output. stdin, stdout, stderr. C Language II. CMSC 313 Sections 01, 02. C opens three input/output devices automatically: C Input/Output stdin, stdout, stderr C opens three input/output devices automatically: C Language II CMSC 313 Sections 01, 02 stdin The "standard input" device, usually your keyboard stdout The "standard

More information

2. Numbers In, Numbers Out

2. Numbers In, Numbers Out COMP1917: Computing 1 2. Numbers In, Numbers Out Reading: Moffat, Chapter 2. COMP1917 15s2 2. Numbers In, Numbers Out 1 The Art of Programming Think about the problem Write down a proposed solution Break

More information

Writing an ANSI C Program Getting Ready to Program A First Program Variables, Expressions, and Assignments Initialization The Use of #define and

Writing an ANSI C Program Getting Ready to Program A First Program Variables, Expressions, and Assignments Initialization The Use of #define and Writing an ANSI C Program Getting Ready to Program A First Program Variables, Expressions, and Assignments Initialization The Use of #define and #include The Use of printf() and scanf() The Use of printf()

More information

Approximately a Final Exam CPSC 206

Approximately a Final Exam CPSC 206 Approximately a Final Exam CPSC 206 Sometime in History based on Kelley & Pohl Last name, First Name Last 4 digits of ID Write your section number: All parts of this exam are required unless plainly and

More information

Chapter 2: Basic Elements of C++

Chapter 2: Basic Elements of C++ Chapter 2: Basic Elements of C++ Objectives In this chapter, you will: Become familiar with functions, special symbols, and identifiers in C++ Explore simple data types Discover how a program evaluates

More information

C programming basics T3-1 -

C programming basics T3-1 - C programming basics T3-1 - Outline 1. Introduction 2. Basic concepts 3. Functions 4. Data types 5. Control structures 6. Arrays and pointers 7. File management T3-2 - 3.1: Introduction T3-3 - Review of

More information

Input/Output and the Operating Systems

Input/Output and the Operating Systems Input/Output and the Operating Systems Fall 2015 Jinkyu Jeong (jinkyu@skku.edu) 1 I/O Functions Formatted I/O printf( ) and scanf( ) fprintf( ) and fscanf( ) sprintf( ) and sscanf( ) int printf(const char*

More information

BSM540 Basics of C Language

BSM540 Basics of C Language BSM540 Basics of C Language Chapter 4: Character strings & formatted I/O Prof. Manar Mohaisen Department of EEC Engineering Review of the Precedent Lecture To explain the input/output functions printf()

More information

C Programming Multiple. Choice

C Programming Multiple. Choice C Programming Multiple Choice Questions 1.) Developer of C language is. a.) Dennis Richie c.) Bill Gates b.) Ken Thompson d.) Peter Norton 2.) C language developed in. a.) 1970 c.) 1976 b.) 1972 d.) 1980

More information

Computers Programming Course 5. Iulian Năstac

Computers Programming Course 5. Iulian Năstac Computers Programming Course 5 Iulian Năstac Recap from previous course Classification of the programming languages High level (Ada, Pascal, Fortran, etc.) programming languages with strong abstraction

More information

Lecture 3. More About C

Lecture 3. More About C Copyright 1996 David R. Hanson Computer Science 126, Fall 1996 3-1 Lecture 3. More About C Programming languages have their lingo Programming language Types are categories of values int, float, char Constants

More information

Programming in C. Session 8. Seema Sirpal Delhi University Computer Centre

Programming in C. Session 8. Seema Sirpal Delhi University Computer Centre Programming in C Session 8 Seema Sirpal Delhi University Computer Centre File I/O & Command Line Arguments An important part of any program is the ability to communicate with the world external to it.

More information

C OVERVIEW. C Overview. Goals speed portability allow access to features of the architecture speed

C OVERVIEW. C Overview. Goals speed portability allow access to features of the architecture speed C Overview C OVERVIEW Goals speed portability allow access to features of the architecture speed C fast executables allows high-level structure without losing access to machine features many popular languages

More information

CS102: Standard I/O. %<flag(s)><width><precision><size>conversion-code

CS102: Standard I/O. %<flag(s)><width><precision><size>conversion-code CS102: Standard I/O Our next topic is standard input and standard output in C. The adjective "standard" when applied to "input" or "output" could be interpreted to mean "default". Typically, standard output

More information

Fundamentals of C. Structure of a C Program

Fundamentals of C. Structure of a C Program Fundamentals of C Structure of a C Program 1 Our First Simple Program Comments - Different Modes 2 Comments - Rules Preprocessor Directives Preprocessor directives start with # e.g. #include copies a file

More information

Computational Methods of Scientific Programming Fall 2007

Computational Methods of Scientific Programming Fall 2007 MIT OpenCourseWare http://ocw.mit.edu 12.010 Computational Methods of Scientific Programming Fall 2007 For information about citing these materials or our Terms of Use, visit: http://ocw.mit.edu/terms.

More information

C OVERVIEW BASIC C PROGRAM STRUCTURE. C Overview. Basic C Program Structure

C OVERVIEW BASIC C PROGRAM STRUCTURE. C Overview. Basic C Program Structure C Overview Basic C Program Structure C OVERVIEW BASIC C PROGRAM STRUCTURE Goals The function main( )is found in every C program and is where every C program begins speed execution portability C uses braces

More information

UNIT-I Input/ Output functions and other library functions

UNIT-I Input/ Output functions and other library functions Input and Output functions UNIT-I Input/ Output functions and other library functions All the input/output operations are carried out through function calls. There exists several functions that become

More information

Chapter 2, Part I Introduction to C Programming

Chapter 2, Part I Introduction to C Programming Chapter 2, Part I Introduction to C Programming C How to Program, 8/e, GE 2016 Pearson Education, Ltd. All rights reserved. 1 2016 Pearson Education, Ltd. All rights reserved. 2 2016 Pearson Education,

More information

CS113: Lecture 3. Topics: Variables. Data types. Arithmetic and Bitwise Operators. Order of Evaluation

CS113: Lecture 3. Topics: Variables. Data types. Arithmetic and Bitwise Operators. Order of Evaluation CS113: Lecture 3 Topics: Variables Data types Arithmetic and Bitwise Operators Order of Evaluation 1 Variables Names of variables: Composed of letters, digits, and the underscore ( ) character. (NO spaces;

More information

9/5/2018. Overview. The C Programming Language. Transitioning to C from Python. Why C? Hello, world! Programming in C

9/5/2018. Overview. The C Programming Language. Transitioning to C from Python. Why C? Hello, world! Programming in C Overview The C Programming Language (with material from Dr. Bin Ren, William & Mary Computer Science) Motivation Hello, world! Basic Data Types Variables Arithmetic Operators Relational Operators Assignments

More information

BITG 1233: Introduction to C++

BITG 1233: Introduction to C++ BITG 1233: Introduction to C++ 1 Learning Outcomes At the end of this lecture, you should be able to: Identify basic structure of C++ program (pg 3) Describe the concepts of : Character set. (pg 11) Token

More information

c) Comments do not cause any machine language object code to be generated. d) Lengthy comments can cause poor execution-time performance.

c) Comments do not cause any machine language object code to be generated. d) Lengthy comments can cause poor execution-time performance. 2.1 Introduction (No questions.) 2.2 A Simple Program: Printing a Line of Text 2.1 Which of the following must every C program have? (a) main (b) #include (c) /* (d) 2.2 Every statement in C

More information

UNIT IV-2. The I/O library functions can be classified into two broad categories:

UNIT IV-2. The I/O library functions can be classified into two broad categories: UNIT IV-2 6.0 INTRODUCTION Reading, processing and writing of data are the three essential functions of a computer program. Most programs take some data as input and display the processed data, often known

More information

Objectives. In this chapter, you will:

Objectives. In this chapter, you will: Objectives In this chapter, you will: Become familiar with functions, special symbols, and identifiers in C++ Explore simple data types Discover how a program evaluates arithmetic expressions Learn about

More information

Computer Science & Information Technology (CS) Rank under AIR 100. Examination Oriented Theory, Practice Set Key concepts, Analysis & Summary

Computer Science & Information Technology (CS) Rank under AIR 100. Examination Oriented Theory, Practice Set Key concepts, Analysis & Summary GATE- 2016-17 Postal Correspondence 1 C-Programming Computer Science & Information Technology (CS) 20 Rank under AIR 100 Postal Correspondence Examination Oriented Theory, Practice Set Key concepts, Analysis

More information

C - Basic Introduction

C - Basic Introduction C - Basic Introduction C is a general-purpose high level language that was originally developed by Dennis Ritchie for the UNIX operating system. It was first implemented on the Digital Equipment Corporation

More information

Programming & Data Structure

Programming & Data Structure File Handling Programming & Data Structure CS 11002 Partha Bhowmick http://cse.iitkgp.ac.in/ pb CSE Department IIT Kharagpur Spring 2012-2013 File File Handling File R&W argc & argv (1) A file is a named

More information

H192 Midterm 1 Review. Tom Zajdel

H192 Midterm 1 Review. Tom Zajdel H192 Midterm 1 Review Tom Zajdel Declaring variables Need to specify a type when declaring a variable. Can declare multiple variables in one line. int x, y, z; float a, b, c; Can also initialize in same

More information

Muntaser Abulafi Yacoub Sabatin Omar Qaraeen. C Data Types

Muntaser Abulafi Yacoub Sabatin Omar Qaraeen. C Data Types Programming Fundamentals for Engineers 0702113 5. Basic Data Types Muntaser Abulafi Yacoub Sabatin Omar Qaraeen 1 2 C Data Types Variable definition C has a concept of 'data types' which are used to define

More information

The C Programming Language. (with material from Dr. Bin Ren, William & Mary Computer Science)

The C Programming Language. (with material from Dr. Bin Ren, William & Mary Computer Science) The C Programming Language (with material from Dr. Bin Ren, William & Mary Computer Science) 1 Overview Motivation Hello, world! Basic Data Types Variables Arithmetic Operators Relational Operators Assignments

More information

Chapter 11 Introduction to Programming in C

Chapter 11 Introduction to Programming in C C: A High-Level Language Chapter 11 Introduction to Programming in C Original slides from Gregory Byrd, North Carolina State University Modified slides by Chris Wilcox, Colorado State University! Gives

More information

Pointers cause EVERYBODY problems at some time or another. char x[10] or char y[8][10] or char z[9][9][9] etc.

Pointers cause EVERYBODY problems at some time or another. char x[10] or char y[8][10] or char z[9][9][9] etc. Compound Statements So far, we ve mentioned statements or expressions, often we want to perform several in an selection or repetition. In those cases we group statements with braces: i.e. statement; statement;

More information

C mini reference. 5 Binary numbers 12

C mini reference. 5 Binary numbers 12 C mini reference Contents 1 Input/Output: stdio.h 2 1.1 int printf ( const char * format,... );......................... 2 1.2 int scanf ( const char * format,... );.......................... 2 1.3 char

More information

Chapter 2: Overview of C. Problem Solving & Program Design in C

Chapter 2: Overview of C. Problem Solving & Program Design in C Chapter 2: Overview of C Problem Solving & Program Design in C Addison Wesley is an imprint of Why Learn C? Compact, fast, and powerful High-level Language Standard for program development (wide acceptance)

More information

Data Type Fall 2014 Jinkyu Jeong

Data Type Fall 2014 Jinkyu Jeong Data Type Fall 2014 Jinkyu Jeong (jinkyu@skku.edu) 1 Syntax Rules Recap. keywords break double if sizeof void case else int static... Identifiers not#me scanf 123th printf _id so_am_i gedd007 Constants

More information

Standard I/O in C and C++

Standard I/O in C and C++ Introduction to Computer and Program Design Lesson 7 Standard I/O in C and C++ James C.C. Cheng Department of Computer Science National Chiao Tung University Standard I/O in C There three I/O memory buffers

More information

C++ Programming: From Problem Analysis to Program Design, Third Edition

C++ Programming: From Problem Analysis to Program Design, Third Edition C++ Programming: From Problem Analysis to Program Design, Third Edition Chapter 2: Basic Elements of C++ Objectives (continued) Become familiar with the use of increment and decrement operators Examine

More information