Outline. Computer Programming. Preprocessing in C. File inclusion. Preprocessing in C

Size: px
Start display at page:

Download "Outline. Computer Programming. Preprocessing in C. File inclusion. Preprocessing in C"

Transcription

1 Outline Computer Programming The greatest gift you can give another is the purity of your attention. Richard Moss Preprocessing in C Function vs macro Conditional compilation Constant identifiers Standard I/O getch, getche, putch (non-portable) gets, puts scanf, printf sscanf, sprintf getchar, putchar Expressions Definition Evaluation T.U. Cluj-Napoca - Computer Programming - lecture 4 - M. Joldoş 1 T.U. Cluj-Napoca - Computer Programming - lecture 4 - M. Joldoş 2 Preprocessing in C Preprocessing occurs before compilation Text substitution in source code according to directives Directives are preceded by the sharp character, i.e. # Preprocessing ensures: Source file inclusion (typically header files) Macro definition and invocation Conditional compilation T.U. Cluj-Napoca - Computer Programming - lecture 4 - M. Joldoş 3 Preprocessing in C. File inclusion The inclusion directive is specified as: #include <file_specifier> or #include file_specifier The directive is replaced by the specified file Notes: An included file may contain include directives Include directives are placed at the top of a file, for visibility of definitions in the whole file Include directives are widely used for large programs Examples #include <stdlib.h> #include my_header.h T.U. Cluj-Napoca - Computer Programming - lecture 4 - M. Joldoş 4

2 Preprocessing in C. Symbolic constant and macro definitions Directive used is #define Defining a symbolic constant is a special case of macro definition #define name character_sequence During preprocessing, name is replaced by character_sequence character_sequence may be more than one line long; continuation using \ as the last character Replacement continues till a directive #undef name or the EOF is met Preprocessing in C. Symbolic constant examples Examples: #define ALPHA 20 #define BETA ALPHA+80 Note: with this definitions x=3*beta is replaced by x=3*20+80 if that is not the intended behavior, BETA should be defined as #define BETA (ALPHA+80) Name is replaced by the character sequence which starts with the first non-whitespace T.U. Cluj-Napoca - Computer Programming - lecture 4 - M. Joldoş 5 T.U. Cluj-Napoca - Computer Programming - lecture 4 - M. Joldoş 6 Preprocessing in C. Macro definitions A macro definition resembles a function definition, i.e. #define name(p1, p2,..., pn) text where name = macro name p1, p2,..., pn = macro parameters text = substitution text Notes Formal parameters are replaced by actual parameters in replacement text text may spread over multiple lines. Continuation with \ as last character Macro substitution is also called expansion A symbolic constant is actually a parameter less macro Invocation is similar with function invocation, i.e. name(p_actual1, p_actual2,..., p_actualn) T.U. Cluj-Napoca - Computer Programming - lecture 4 - M. Joldoş 7 Preprocessing in C. Macro definition examples Swapping two variables: Definition #define SWAP(vartype, a, b) (vartype t;\ t=a; a=b; b=t; ) Invocation SWAP(int, x, y) SWAP(double, u, v) Calculate the absolute value Definition #define ABS(x) ( (x) < 0? (x) : (x) ) Invocation k= ABS(a - b); Expansion. Note that x is replaced by a - b k= ( (a - b) < 0? (a b) : (a b) ); T.U. Cluj-Napoca - Computer Programming - lecture 4 - M. Joldoş 8

3 Preprocessing in C. Function vs. macro Differences between functions and macro definitions Function invocation involves a call and execution of statements of function body Upon function invocation parameter type is also considered Macro invocation means expansion, i.e. replacement of invocation with macro text. Thus statements in a macro are generated for each invocation and compiled. Hence, macros should be used for small size computations Upon macro invocation, a formal parameter is replaced by the character sequence corresponding to the actual parameter. Formalactual parameter correspondence is purely positional Processing time is shorter when using macros (function invocation requires overhead) Note. C++ also has inline functions, based on a principle similar to macros with the difference that type is also considered T.U. Cluj-Napoca - Computer Programming - lecture 4 - M. Joldoş 9 Preprocessing in C. Conditional compilation Conditional compilation facilitates development, mainly testing Directives for conditional compilation: #if: #if expr #if expr text text1 #else text2 where expr is a constant expression which can be evaluated by the preprocessor, text1, text2, text are portions of source code Effect: if expr is not zero text (text1) are compiled (not text2). Otherwise only text2 (for second form) and processing continues after T.U. Cluj-Napoca - Computer Programming - lecture 4 - M. Joldoş 10 Preprocessing in C. Conditional compilation Directives for conditional compilation: #ifdef: #ifdef name text #ifdef name text1 #else text2 where name is a constant which is tested if defined; text1, text2, text are portions of source code Effect: if name is defined text (text1) are compiled (not text2). Otherwise only text2 (for second form) and processing continues after Preprocessing in C. Conditional compilation Directives for conditional compilation: #ifndef: #ifndef name text #ifndef name text1 #else text2 where name is a constant which is tested if not defined; text1, text2, text are portions of source code Effect: if name is undefined text (text1) are compiled (not text2). Otherwise only text2 (for second form) and processing continues after T.U. Cluj-Napoca - Computer Programming - lecture 4 - M. Joldoş 11 T.U. Cluj-Napoca - Computer Programming - lecture 4 - M. Joldoş 12

4 Preprocessing in C. Conditional compilation #ifdef and #ifndef are used to avoid multiple inclusions. Thus at the beginning of each header file sequences similar to the following can be present (excerpt from stdio.h): #ifndef _STDIO_H_ #define _STDIO_H_... /* _STDIO_H_ */ Note. A number of predefined names exist, e.g.: MSDOS if operating system is MSDOS DATE date of compilation CDECL -indicates that function calls follow C conventions STDC - defined if strict C ANSI rules must be followed FILE - name of currently compiled file T.U. Cluj-Napoca - Computer Programming - lecture 4 - M. Joldoş 13 Preprocessing in C. Declaring constant identifiers #error: causes a compilation error with a message given as a parameter to it. E.g. #ifndef cplusplus #error This program should be compiled with C++\ compilers Constant declaration: type const identifier=value; or const type identifier=value; Examples: int const alpha=10; double const beta=20.5; or const int alpha=10; const double beta=20.5; T.U. Cluj-Napoca - Computer Programming - lecture 4 - M. Joldoş 14 Standard I/O functions If interactive processing, then: The standard terminal is the terminal used to run the program. Three files are attached to it: Input file (stdin) Output file (stdout) Error file (stderr) C/C++ do not have statements for reading and writing. I/O operations are achieved by functions with prototypes in stdio.h Note: conio.h is an extension, it is NOT part of the standard Non-portable functions: getch, getche, putch Character oriented getch: reads without echoing a character from stdin getche: similar, but echoes its input For both execution waits for a new character to become available putch: prints the character whose ASCII code is its parameter Printable characters have codes in the range [32, 126] Prototypes in conio.h: int getch(void); int getche(void); int putch(int ch); T.U. Cluj-Napoca - Computer Programming - lecture 4 - M. Joldoş T.U. Cluj-Napoca - Computer Programming - lecture 4 - M. Joldoş 16

5 Non-portable functions: getch, getche, putch Example: #include <conio.h> /* non-portable! */ int main(void) { putch( \r ); putch( \n ); /* CR+LF */ putch(getch()); putch( \r ); putch( \n ); /* CR+LF */ putch(getche()); getch(); return 0; } T.U. Cluj-Napoca - Computer Programming - lecture 4 - M. Joldoş 17 gets: Function gets Reads characters from the stream stdin up to the next newline character, and stores them in the string given as argument The newline character is discarded. If gets encounters a read error or end-of-file, it returns a null pointer; otherwise it returns its argument. Warning: The gets function is very dangerous because it provides no protection against overflowing the string s. The GNU library includes it for compatibility only. You should always use fgets or getline instead. Prototype: char *gets(char *s); T.U. Cluj-Napoca - Computer Programming - lecture 4 - M. Joldoş 18 puts: Functions gets Writes the string given as an argument to the stream stdout followed by a newline. The terminating null character of the string is not written. puts is the most convenient function for printing simple messages. Returns the code of the last output character Prototype: int puts(const char *s); Functions gets and puts. Example #include <stdio.h> #include <stdlib.h> int main(void) { char s[200]; printf( \ninput a character string and press Enter\n ); gets(s); /* the character string is stored at the address where s points */ printf( \nthe string you input is:\n ); puts(s); system( PAUSE ); return 0; } T.U. Cluj-Napoca - Computer Programming - lecture 4 - M. Joldoş 19 T.U. Cluj-Napoca - Computer Programming - lecture 4 - M. Joldoş 20

6 scanf Function scanf reads formatted input from the stream stdin under the control of the template string given as its first argument. The next arguments are optional arguments, and are pointers to the places which receive the resulting values. The return value is normally the number of successful assignments. If an end-of-file condition is detected before any matches are performed, including matches against whitespace and literal characters in the template, then EOF is returned. Prototype: int scanf(const char *template, pointer ); T.U. Cluj-Napoca - Computer Programming - lecture 4 - M. Joldoş 21 Function scanf. Template string A scanf template string contains format specifiers A scanf template string has the general form: % flags width type conversion In more detail, an input conversion specification consists of an initial '%' character followed in sequence by: An optional flag character, *, which says to ignore the text read for this specification. An optional decimal integer that specifies the maximum field width. Reading of characters from the input stream stops either when this maximum is reached or when a non-matching character is found, whichever happens first. Most conversions discard initial whitespace characters (those that don't are explicitly documented), and these discarded characters don't count towards the maximum field width. String input conversions store a null character to mark the end of the input; the maximum field width does not include this terminator. An optional type modifier character. A character that specifies the conversion to be applied. T.U. Cluj-Napoca - Computer Programming - lecture 4 - M. Joldoş 22 Table of input conversions (1) %d %i %o %u %x, %X Function scanf. Table of output conversions I %e, %f, %g, %E, %G Matches an optionally signed integer written in decimal. Matches an optionally signed integer in any of the formats that the C language defines for specifying an integer constant. Matches an unsigned integer written in octal radix. Matches an unsigned integer written in decimal radix Matches an unsigned integer written in hexadecimal radix. Matches an optionally signed floating-point number. T.U. Cluj-Napoca - Computer Programming - lecture 4 - M. Joldoş 23 Table of input conversions (2) %s %[ %c %p %n %% Function scanf. Table of output conversions II Matches a string containing only non-whitespace characters Matches a string of characters that belong to a specified set. Matches a string of one or more characters; the number of characters read is controlled by the maximum field width given for the conversion. Matches a pointer value in the same implementationdefined format used by the %p output conversion for printf. This conversion doesn't read any characters; it records the number of characters read so far by this call. Matches an literal % given in the input stream T.U. Cluj-Napoca - Computer Programming - lecture 4 - M. Joldoş 24

7 Scan sets Function scanf. Scan sets Set of characters enclosed in square brackets [] Preceded by % sign Scans input stream, looking only for characters in scan set Whenever a match occurs, stores character in specified array Stops scanning once a character not in the scan set is found Inverted scan sets Use a caret ^: "%[^aeiou]" Causes characters not in the scan set to be stored Skipping characters Include character to skip in format control Or, use * (assignment suppression character) Skips any type of character without storing it T.U. Cluj-Napoca - Computer Programming - lecture 4 - M. Joldoş 25 Function scanf. Examples Usage examples for scanf Read a character char ch; scanf( %c, &ch); Read a character string char s[40]; scanf( %s, s); Read three integers with values in decimal, octal, and hexadecimal respectively int a, b, c; scanf( %d %o %x, &a, &b, &c); Read reals of type float, double, long double float x; double y; long double z; scanf( %f %lf %Lf, &x, &y, &z); T.U. Cluj-Napoca - Computer Programming - lecture 4 - M. Joldoş 26 printf Function printf prints the optional arguments under the control of the template string template to the stream stdout. returns the number of characters printed, or a negative value if there was an output error. Prototype: int printf (const char *template,...) expression_list ); T.U. Cluj-Napoca - Computer Programming - lecture 4 - M. Joldoş 27 Function printf. Template string I A printf template string contains format specifiers A printf template string has the general form: % param-no $ flags width. precision type conversion In more detail, an output conversion specification consists of an initial % character followed in sequence by: An optional specification of the parameter used for this format. Normally the parameters to the printf function are assigned to the formats in the order of appearance in the format string. The param-no part of the format must be an integer in the range of 1 to the maximum number of arguments present to the function call. Zero or more flag characters that modify the normal behavior of the conversion specification. An optional decimal integer that specifies the minimum field width. This is a minimum value; if the normal conversion produces more characters than this, the field is not truncated. Normally, the output is right-justified within the field. You can also specify a field width of *. This means that the next argument in the argument list (before the actual value to be printed) is used as the field width. The value must be an int. If the value is negative, this means to set the flag and to use the absolute value as the field width. T.U. Cluj-Napoca - Computer Programming - lecture 4 - M. Joldoş 28

8 Function printf. Template string II printf template string format specifiers (cont d) An optional precision to specify the number of digits to be written for the numeric conversions. If the precision is specified, it consists of a period (.) followed optionally by a decimal integer (which defaults to zero if omitted). You can also specify a precision of *. This means that the next argument in the argument list (before the actual value to be printed) is used as the precision. The value must be an int, and is ignored if it is negative. If you specify * for both the field width and precision, the field width argument precedes the precision argument. C library versions other than GNU may not recognize this syntax. An optional type modifier character, which is used to specify the data type of the corresponding argument if it differs from the default type. (For example, the integer conversions assume a type of int, but you can specify h, l, or L for other integer types.) A character that specifies the conversion to be applied. Conversion characters are the same as for scanf, except for %[ which is not used here T.U. Cluj-Napoca - Computer Programming - lecture 4 - M. Joldoş 29 Table of output conversions (1) %d %i %u %o %x %X %f %e, %E, %g, %G Function printf. Table of output conversions I Print an integer as a signed decimal number. Print an integer as an unsigned decimal number. Print an integer as an unsigned octal number. Print an integer as an unsigned hexadecimal number. %x uses lower-case letters and %X uses upper-case. Print a floating-point number in normal (fixed-point) notation Print a floating-point number in exponential notation. %e uses lower-case letters and %E uses upper-case. Print a floating-point number in either normal or exponential notation, whichever is more appropriate for its magnitude. %g uses lower-case letters and %G uses upper-case. T.U. Cluj-Napoca - Computer Programming - lecture 4 - M. Joldoş 30 Table of output conversions (2) %a %A %c %s %p %n Function printf. Table of output conversions II Print a floating-point number in a hexadecimal fractional notation which the exponent to base 2 represented in decimal digits. %a uses lower-case letters and %A uses upper-case. Print a single character. Print a string. Print the value of a pointer. Get the number of characters printed so far. Function printf. Flags for integer conversions Modifier flags for integer conversions: : Left-justify the result in the field (instead of the normal right-justification). +: For the signed %d and %i conversions, print a plus sign if the value is positive. #: For %o conversion, forces the leading digit to be 0, as if by increasing the precision. For %x or %X, prefixes a leading 0x or 0X to the result. Doesn't do anything useful for the %d, %i, or %u conversions. 0: Pad the field with zeros instead of spaces. The zeros are placed after any indication of sign or base. This flag is ignored if the flag is also specified, or if a precision is specified. T.U. Cluj-Napoca - Computer Programming - lecture 4 - M. Joldoş 31 T.U. Cluj-Napoca - Computer Programming - lecture 4 - M. Joldoş 32

9 Function printf. Example: integer Example of integer numbers printing (from libc help) Values printed are, in order: 0, 1, -1, Specifier: " %5d %-5d %+5d %+-5d % 5d %05d %5.0d %5.2d %d \n Output: Specifier: " %5u %5o %5x %5X %#5o %#5x %#5X %#10.8x \n" Output: x1 0X1 0x a0 186A x186a0 0X186A0 0x000186a0 Function printf. Flags for integer conversions Modifier flags for floating point number conversions : Left-justify the result in the field. Normally the result is rightjustified. +: Always include a plus or minus sign in the result. If the result doesn't start with a plus or minus sign, prefix it with a space instead. Since the + flag ensures that the result includes a sign, this flag is ignored if you supply both of them. #: Specifies that the result should always include a decimal point, even if no digits follow it. For the %g and %G conversions, this also forces trailing zeros after the decimal point to be left in place where they would otherwise be removed. 0: Pad the field with zeros instead of spaces; the zeros are placed after any sign. This flag is ignored if the '-' flag is also specified. A type modifier is supported: L An uppercase L specifies that the argument is a long double. T.U. Cluj-Napoca - Computer Programming - lecture 4 - M. Joldoş 33 T.U. Cluj-Napoca - Computer Programming - lecture 4 - M. Joldoş 34 Function printf. Example: floating point Example of floating number printing (from libc help) Values printed are, in order:0, 0.5, 1, -1, 100, 1000, 10000, 12345, , Specifier: " %13.4a %13.4f %13.4e %13.4g \n" Output: 0x0.0000p e x1.0000p e x1.0000p e x1.0000p e x1.9000p e x1.f400p e x1.3880p e+04 1e+04 0x1.81c8p e e+04 0x1.86a0p e+05 1e+05 0x1.e240p e e+05 printf. Printing literals and escape sequences Escape sequence Description \' Output the single quote (') character. \" Output the double quote (") character. \? Output the question mark (?) character. \\ Output the backslash (\) character. \a Cause an audible (bell) or visual alert. \b Move the cursor back one position on the current line. \f Move the cursor to the start of the next logical page. \n Move the cursor to the beginning of the next line. \r Move the cursor to the beginning of the current line. \t Move the cursor to the next horizontal tab position. \v Move the cursor to the next vertical tab position. T.U. Cluj-Napoca - Computer Programming - lecture 4 - M. Joldoş 35 T.U. Cluj-Napoca - Computer Programming - lecture 4 - M. Joldoş 36

10 scanf and printf example #include <stdio.h> #include <stdlib.h> int main(void) { int a, e1, e2; float b, c, d; printf( \ninput an integer value a= ); scanf( %d, &a); printf( \ninput a real value b= ); scanf( %f, &b); c=a+b; e1=a+b; d=a*b; e2=a+b; printf( \nc=%d+%.3f=%.3f d=%d*%.3f=%.3f\n, a, b, c, a, b, d); printf( \ne1=%d+%f=%d e2=%d*%f=%d\nnote that truncation\ occurs\n, a, b, e1, a, b, e2); system( Pause ); return 0; } T.U. Cluj-Napoca - Computer Programming - lecture 4 - M. Joldoş 37 sscanf and sprintf Have an extra parameter: the address of the memory area (a buffer) containing the input (ASCII) to be converted sscanf converts the content of that area instead of stdin sprintf outputs to that area instead of stdout Prototypes (found in stdio.h) int sscanf(const char *buffer, const char *template, pointer ); int sprintf(const char *buffer, const char *template, variable_list); T.U. Cluj-Napoca - Computer Programming - lecture 4 - M. Joldoş 38 sscanf and sprintf example #include <stdio.h> #include <stdlib.h> int main(void) { char s[100], q[100]; int a, b; float c, d; printf( \ninput the values for a and c on a single line\nseparated by a space, then press Enter\n ); gets(s); /* a string containing a and c is found at address s */ sscanf(s, %d %f, &a, &c); printf( \na=%4d c=%8.3f\n, a, c); sprintf(q, \na=%4d c=%8.3f\n, a, c); /* q contains a string which includes the values of a and c */ sscanf(q, %d %f, &b, &d); /* now b=a and d=c */ printf( \na=%4d c=%8.3f\n, b, d); system( Pause ); return 0; } T.U. Cluj-Napoca - Computer Programming - lecture 4 - M. Joldoş 39 Macros getchar and putchar getchar reads a single character from stdin. Returns the ASCII code of the character or -1 when EOF is encountered putchar writes a single character, given as an argument, to stdout. Returns the value of the character given as an argument Prototypes: int getchar(void); int putchar (int c); Usage example #include <stdio.h> #include <stdlib.h> int main(void) { putchar( \r ); putchar( \n ); /* begin new line */ putchar(getchar(())) putchar( \r ); putchar( \n ); /* begin new line */ system( Pause ); return 0; } T.U. Cluj-Napoca - Computer Programming - lecture 4 - M. Joldoş 40

11 Expressions Expression=one or more operands joined by operators An operand can be: A numeric or a character constant A symbolic constant A simple variable identifier An array identifier A structure identifier A type identifier A function identifier An indexed variable A component of a structure A function call An expression enclosed between parenthesis Expressions An operand Has a type and a value An operator Can be unary or binary Unary: applied to a single operand Binary: applied to both preceding and following operand Does not have any effect on character string constants T.U. Cluj-Napoca - Computer Programming - lecture 4 - M. Joldoş 41 T.U. Cluj-Napoca - Computer Programming - lecture 4 - M. Joldoş 42 Expressions. Operators Operators are grouped in classes Arithmetic operators: unary + and binary + * / % Relation operators < <= > >= Equality operators ==!= Logic operators: negation!, and &&, or Bitwise operators: one s complement ~, left shift <<, right shift >>, and &, or, exclusive or ^ Assignment operators: assignment =; compound assignment: op= where op is an arithmetic or bitwise operator. The effect is: v op = operand v = v op operand Expressions. Operators Operators are grouped in classes (cont d) Increment/decrement operators: ++, Type cast operators: (type) operand Size operator: sizeof(variable), sizeof(type ) Referencing operator: &identifier Parenthesis operator: () [] Conditional operator:? : (expression? exp1: exp2) Comma operator:, Dereferencing operators: *,., -> C++ specific: Memory allocation/free: new/delete Resolution: :: T.U. Cluj-Napoca - Computer Programming - lecture 4 - M. Joldoş 43 T.U. Cluj-Napoca - Computer Programming - lecture 4 - M. Joldoş 44

12 Expression evaluation What is taken into account: Operator priority Operator associativity for equal priority Default conversion rule Descending order of type priority: long double double float unsigned long long unsigned int Expression evaluation The result of evaluating relational expressions is true or false. False is represented by zero, true by non-zero Increment and decrement operators can be prefix (++operand) or postfix (operand--) Prefix: in evaluation the value after increment/decrement is used, e.g. x=10; y=++x; /* y=11 and x=11 */ Postfix: the value before increment/decrement is used in evaluation x=10; z=x++; /* z=10 and x=11 */ Comma operator. The expressions are evaluated strictly left to right and their values discarded, except for the last one, whose type and value determine the result of the overall expression. Usage examples (for decomposition of complex evaluations): y=((c=(a<0)? a: a), (d=(b<0)? -b: b), (c>d)? c: d); alpha = ((a1=x+y+z), (a2=x+y+w), (a1*a2+10)); T.U. Cluj-Napoca - Computer Programming - lecture 4 - M. Joldoş 45 T.U. Cluj-Napoca - Computer Programming - lecture 4 - M. Joldoş 46 Logical operators. Truth tables Truth table for the && (logical AND) operator. expression1 expression nonzero 0 nonzero 0 0 nonzero nonzero 1 expression1 && expression2 Truth table for the logical OR ( ) operator. expression1 expression2 expression nonzero 1 nonzero 0 1 nonzero nonzero 1 Truth table for operator! (logical negation). expression 0 1 nonzero 0 expression2! expression T.U. Cluj-Napoca - Computer Programming - lecture 4 - M. Joldoş 47 Level Operator precedence and associativity Operator(s) Description Associativity :: global scope (unary) :: class scope (binary) ->. member selectors [ ] array index ( ) function call ( ) type construction sizeof size in bytes increment, decrement ~ bitwise NOT! logical NOT + - unary plus, minus * & dereference, address-of ( ) cast new delete free store management ->*.* member pointer selectors T.U. Cluj-Napoca - Computer Programming - lecture 4 - M. Joldoş 48

13 Operator precedence and associativity Summary Level Operator(s) * / % + - << >> < <= > >= ==!= & ^ &&? : = *= /* %= += -= <<= >>= &= = ^= Description multiplicative operators arithmetic operators bitwise shift relational operators equality, inequality bitwise AND bitwise exclusive OR bitwise inclusive OR logical AND logical OR arithmetic if assignment operators Associativity Preprocessing in C Function vs. macro Conditional compilation Constant identifiers Standard I/O getch, getche, putch (non-portable) gets, puts scanf, printf sscanf, sprintf getchar, putchar Expressions Definition Evaluation 1, comma operator T.U. Cluj-Napoca - Computer Programming - lecture 4 - M. Joldoş 49 T.U. Cluj-Napoca - Computer Programming - lecture 4 - M. Joldoş 50

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

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

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

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

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

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

UNIT 3 OPERATORS. [Marks- 12]

UNIT 3 OPERATORS. [Marks- 12] 1 UNIT 3 OPERATORS [Marks- 12] SYLLABUS 2 INTRODUCTION C supports a rich set of operators such as +, -, *,,

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

Unit 4. Input/Output Functions

Unit 4. Input/Output Functions Unit 4 Input/Output Functions Introduction to Input/Output Input refers to accepting data while output refers to presenting data. Normally the data is accepted from keyboard and is outputted onto the screen.

More information

Goals of C "" The Goals of C (cont.) "" Goals of this Lecture"" The Design of C: A Rational Reconstruction"

Goals of C  The Goals of C (cont.)  Goals of this Lecture The Design of C: A Rational Reconstruction Goals of this Lecture The Design of C: A Rational Reconstruction Help you learn about: The decisions that were available to the designers of C The decisions that were made by the designers of C Why? Learning

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

Computers Programming Course 6. Iulian Năstac

Computers Programming Course 6. Iulian Năstac Computers Programming Course 6 Iulian Năstac Recap from previous course Data types four basic arithmetic type specifiers: char int float double void optional specifiers: signed, unsigned short long 2 Recap

More information

Arithmetic Operators. Portability: Printing Numbers

Arithmetic Operators. Portability: Printing Numbers Arithmetic Operators Normal binary arithmetic operators: + - * / Modulus or remainder operator: % x%y is the remainder when x is divided by y well defined only when x > 0 and y > 0 Unary operators: - +

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

The Design of C: A Rational Reconstruction (cont.)

The Design of C: A Rational Reconstruction (cont.) The Design of C: A Rational Reconstruction (cont.) 1 Goals of this Lecture Recall from last lecture Help you learn about: The decisions that were available to the designers of C The decisions that were

More information

File Handling in C. EECS 2031 Fall October 27, 2014

File Handling in C. EECS 2031 Fall October 27, 2014 File Handling in C EECS 2031 Fall 2014 October 27, 2014 1 Reading from and writing to files in C l stdio.h contains several functions that allow us to read from and write to files l Their names typically

More information

Reserved Words and Identifiers

Reserved Words and Identifiers 1 Programming in C Reserved Words and Identifiers Reserved word Word that has a specific meaning in C Ex: int, return Identifier Word used to name and refer to a data element or object manipulated by the

More information

Lecture 4. Console input/output operations. 1. I/O functions for characters 2. I/O functions for strings 3. I/O operations with data formatting

Lecture 4. Console input/output operations. 1. I/O functions for characters 2. I/O functions for strings 3. I/O operations with data formatting Lecture 4 Console input/output operations 1. I/O functions for characters 2. I/O functions for strings 3. I/O operations with data formatting Header files: stdio.h conio.h C input/output revolves around

More information

Should you know scanf and printf?

Should you know scanf and printf? C-LANGUAGE INPUT & OUTPUT C-Language Output with printf Input with scanf and gets_s and Defensive Programming Copyright 2016 Dan McElroy Should you know scanf and printf? scanf is only useful in the C-language,

More information

UNIT IV 2 MARKS. ( Word to PDF Converter - Unregistered ) FUNDAMENTALS OF COMPUTING & COMPUTER PROGRAMMING

UNIT IV 2 MARKS. ( Word to PDF Converter - Unregistered )   FUNDAMENTALS OF COMPUTING & COMPUTER PROGRAMMING ( Word to PDF Converter - Unregistered ) http://www.word-to-pdf-converter.net FUNDAMENTALS OF COMPUTING & COMPUTER PROGRAMMING INTRODUCTION TO C UNIT IV Overview of C Constants, Variables and Data Types

More information

EDIABAS BEST/2 LANGUAGE DESCRIPTION. VERSION 6b. Electronic Diagnostic Basic System EDIABAS - BEST/2 LANGUAGE DESCRIPTION

EDIABAS BEST/2 LANGUAGE DESCRIPTION. VERSION 6b. Electronic Diagnostic Basic System EDIABAS - BEST/2 LANGUAGE DESCRIPTION EDIABAS Electronic Diagnostic Basic System BEST/2 LANGUAGE DESCRIPTION VERSION 6b Copyright BMW AG, created by Softing AG BEST2SPC.DOC CONTENTS CONTENTS...2 1. INTRODUCTION TO BEST/2...5 2. TEXT CONVENTIONS...6

More information

Introduction to C Language

Introduction to C Language Introduction to C Language Instructor: Professor I. Charles Ume ME 6405 Introduction to Mechatronics Fall 2006 Instructor: Professor Charles Ume Introduction to C Language History of C Language In 1972,

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

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

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

CS6202 - PROGRAMMING & DATA STRUCTURES UNIT I Part - A 1. W hat are Keywords? Keywords are certain reserved words that have standard and pre-defined meaning in C. These keywords can be used only for their

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

CSCI 171 Chapter Outlines

CSCI 171 Chapter Outlines Contents CSCI 171 Chapter 1 Overview... 2 CSCI 171 Chapter 2 Programming Components... 3 CSCI 171 Chapter 3 (Sections 1 4) Selection Structures... 5 CSCI 171 Chapter 3 (Sections 5 & 6) Iteration Structures

More information

The Design of C: A Rational Reconstruction (cont.)" Jennifer Rexford!

The Design of C: A Rational Reconstruction (cont.) Jennifer Rexford! The Design of C: A Rational Reconstruction (cont.)" Jennifer Rexford! 1 Goals of this Lecture"" Help you learn about:! The decisions that were available to the designers of C! The decisions that were made

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

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

XC Specification. 1 Lexical Conventions. 1.1 Tokens. The specification given in this document describes version 1.0 of XC.

XC Specification. 1 Lexical Conventions. 1.1 Tokens. The specification given in this document describes version 1.0 of XC. XC Specification IN THIS DOCUMENT Lexical Conventions Syntax Notation Meaning of Identifiers Objects and Lvalues Conversions Expressions Declarations Statements External Declarations Scope and Linkage

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

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

Guide for The C Programming Language Chapter 1. Q1. Explain the structure of a C program Answer: Structure of the C program is shown below:

Guide for The C Programming Language Chapter 1. Q1. Explain the structure of a C program Answer: Structure of the C program is shown below: Q1. Explain the structure of a C program Structure of the C program is shown below: Preprocessor Directives Global Declarations Int main (void) Local Declarations Statements Other functions as required

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

C Programming Language (Chapter 2 of K&R) Variables and Constants

C Programming Language (Chapter 2 of K&R) Variables and Constants C Programming Language (Chapter 2 of K&R) Types, Operators and Expressions Variables and Constants Basic objects manipulated by programs Declare before use: type var1, var2, int x, y, _X, x11, buffer;

More information

INTRODUCTION TO C++ C FORMATTED INPUT/OUTPUT. Dept. of Electronic Engineering, NCHU. Original slides are from

INTRODUCTION TO C++ C FORMATTED INPUT/OUTPUT. Dept. of Electronic Engineering, NCHU. Original slides are from INTRODUCTION TO C++ C FORMATTED INPUT/OUTPUT Original slides are from http://sites.google.com/site/progntut/ Dept. of Electronic Engineering, NCHU Outline 2 printf and scanf Streams (input and output)

More information

Stream Model of I/O. Basic I/O in C

Stream Model of I/O. Basic I/O in C Stream Model of I/O 1 A stream provides a connection between the process that initializes it and an object, such as a file, which may be viewed as a sequence of data. In the simplest view, a stream object

More information

Continued from previous lecture

Continued from previous lecture The Design of C: A Rational Reconstruction: Part 2 Jennifer Rexford Continued from previous lecture 2 Agenda Data Types Statements What kinds of operators should C have? Should handle typical operations

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

Unit 4 Preprocessor Directives

Unit 4 Preprocessor Directives 1 What is pre-processor? The job of C preprocessor is to process the source code before it is passed to the compiler. Source Code (test.c) Pre-Processor Intermediate Code (test.i) Compiler The pre-processor

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

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

Advanced C Programming Topics

Advanced C Programming Topics Introductory Medical Device Prototyping Advanced C Programming Topics, http://saliterman.umn.edu/ Department of Biomedical Engineering, University of Minnesota Operations on Bits 1. Recall there are 8

More information

Basic Types and Formatted I/O

Basic Types and Formatted I/O Basic Types and Formatted I/O C Variables Names (1) Variable Names Names may contain letters, digits and underscores The first character must be a letter or an underscore. the underscore can be used but

More information

Java Notes. 10th ICSE. Saravanan Ganesh

Java Notes. 10th ICSE. Saravanan Ganesh Java Notes 10th ICSE Saravanan Ganesh 13 Java Character Set Character set is a set of valid characters that a language can recognise A character represents any letter, digit or any other sign Java uses

More information

EECS2031. Modifiers. Data Types. Lecture 2 Data types. signed (unsigned) int long int long long int int may be omitted sizeof()

EECS2031. Modifiers. Data Types. Lecture 2 Data types. signed (unsigned) int long int long long int int may be omitted sizeof() Warning: These notes are not complete, it is a Skelton that will be modified/add-to in the class. If you want to us them for studying, either attend the class or get the completed notes from someone who

More information

Operators in java Operator operands.

Operators in java Operator operands. Operators in java Operator in java is a symbol that is used to perform operations and the objects of operation are referred as operands. There are many types of operators in java such as unary operator,

More information

C Input/Output. Before we discuss I/O in C, let's review how C++ I/O works. int i; double x;

C Input/Output. Before we discuss I/O in C, let's review how C++ I/O works. int i; double x; C Input/Output Before we discuss I/O in C, let's review how C++ I/O works. int i; double x; cin >> i; cin >> x; cout

More information

Model Viva Questions for Programming in C lab

Model Viva Questions for Programming in C lab Model Viva Questions for Programming in C lab Title of the Practical: Assignment to prepare general algorithms and flow chart. Q1: What is a flowchart? A1: A flowchart is a diagram that shows a continuous

More information

C++ Programming Basics

C++ Programming Basics C++ Programming Basics Chapter 2 and pp. 634-640 Copyright 1998-2011 Delroy A. Brinkerhoff. All Rights Reserved. CS 1410 Chapter 2 Slide 1 of 25 Program Components Function main P Every C/C++ program has

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

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

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

Mechatronics and Microcontrollers. Szilárd Aradi PhD Refresh of C

Mechatronics and Microcontrollers. Szilárd Aradi PhD Refresh of C Mechatronics and Microcontrollers Szilárd Aradi PhD Refresh of C About the C programming language The C programming language is developed by Dennis M Ritchie in the beginning of the 70s One of the most

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

Introduction. Following are the types of operators: Unary requires a single operand Binary requires two operands Ternary requires three operands

Introduction. Following are the types of operators: Unary requires a single operand Binary requires two operands Ternary requires three operands Introduction Operators are the symbols which operates on value or a variable. It tells the compiler to perform certain mathematical or logical manipulations. Can be of following categories: Unary requires

More information

Week 3 More Formatted Input/Output; Arithmetic and Assignment Operators

Week 3 More Formatted Input/Output; Arithmetic and Assignment Operators Week 3 More Formatted Input/Output; Arithmetic and Assignment Operators Formatted Input and Output The printf function The scanf function Arithmetic and Assignment Operators Simple Assignment Side Effect

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

Lecture 02 C FUNDAMENTALS

Lecture 02 C FUNDAMENTALS Lecture 02 C FUNDAMENTALS 1 Keywords C Fundamentals auto double int struct break else long switch case enum register typedef char extern return union const float short unsigned continue for signed void

More information

Introduction to C++ Introduction and History. Characteristics of C++

Introduction to C++ Introduction and History. Characteristics of C++ Introduction and History Introduction to C++ Until 1980, C programming was widely popular, and slowly people started realizing the drawbacks of this language and at the same time, the engineers had come

More information

The C++ Language. Arizona State University 1

The C++ Language. Arizona State University 1 The C++ Language CSE100 Principles of Programming with C++ (based off Chapter 2 slides by Pearson) Ryan Dougherty Arizona State University http://www.public.asu.edu/~redoughe/ Arizona State University

More information

Chapter 7. Basic Types

Chapter 7. Basic Types Chapter 7 Basic Types Dr. D. J. Jackson Lecture 7-1 Basic Types C s basic (built-in) types: Integer types, including long integers, short integers, and unsigned integers Floating types (float, double,

More information

Types, Operators and Expressions

Types, Operators and Expressions Types, Operators and Expressions EECS 2031 18 September 2017 1 Variable Names (2.1) l Combinations of letters, numbers, and underscore character ( _ ) that do not start with a number; are not a keyword.

More information

Operators and Expressions in C & C++ Mahesh Jangid Assistant Professor Manipal University, Jaipur

Operators and Expressions in C & C++ Mahesh Jangid Assistant Professor Manipal University, Jaipur Operators and Expressions in C & C++ Mahesh Jangid Assistant Professor Manipal University, Jaipur Operators and Expressions 8/24/2012 Dept of CS&E 2 Arithmetic operators Relational operators Logical operators

More information

Programming in C and Data Structures [15PCD13/23] 1. PROGRAMMING IN C AND DATA STRUCTURES [As per Choice Based Credit System (CBCS) scheme]

Programming in C and Data Structures [15PCD13/23] 1. PROGRAMMING IN C AND DATA STRUCTURES [As per Choice Based Credit System (CBCS) scheme] Programming in C and Data Structures [15PCD13/23] 1 PROGRAMMING IN C AND DATA STRUCTURES [As per Choice Based Credit System (CBCS) scheme] Course objectives: The objectives of this course is to make students

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

LESSON 1. A C program is constructed as a sequence of characters. Among the characters that can be used in a program are:

LESSON 1. A C program is constructed as a sequence of characters. Among the characters that can be used in a program are: LESSON 1 FUNDAMENTALS OF C The purpose of this lesson is to explain the fundamental elements of the C programming language. C like other languages has all alphabet and rules for putting together words

More information

Language Reference Manual simplicity

Language Reference Manual simplicity Language Reference Manual simplicity Course: COMS S4115 Professor: Dr. Stephen Edwards TA: Graham Gobieski Date: July 20, 2016 Group members Rui Gu rg2970 Adam Hadar anh2130 Zachary Moffitt znm2104 Suzanna

More information

Introduction to Computing Lecture 03: Basic input / output operations

Introduction to Computing Lecture 03: Basic input / output operations Introduction to Computing Lecture 03: Basic input / output operations Assist.Prof.Dr. Nükhet ÖZBEK Ege University Department of Electrical & Electronics Engineering nukhet.ozbek@ege.edu.tr Topics Streams

More information

SWEN-250 Personal SE. Introduction to C

SWEN-250 Personal SE. Introduction to C SWEN-250 Personal SE Introduction to C A Bit of History Developed in the early to mid 70s Dennis Ritchie as a systems programming language. Adopted by Ken Thompson to write Unix on a the PDP-11. At the

More information

A complex expression to evaluate we need to reduce it to a series of simple expressions. E.g * 7 =>2+ 35 => 37. E.g.

A complex expression to evaluate we need to reduce it to a series of simple expressions. E.g * 7 =>2+ 35 => 37. E.g. 1.3a Expressions Expressions An Expression is a sequence of operands and operators that reduces to a single value. An operator is a syntactical token that requires an action be taken An operand is an object

More information

Problem Solving and 'C' Programming

Problem Solving and 'C' Programming Problem Solving and 'C' Programming Targeted at: Entry Level Trainees Session 15: Files and Preprocessor Directives/Pointers 2007, Cognizant Technology Solutions. All Rights Reserved. The information contained

More information

Contents. Preface. Introduction. Introduction to C Programming

Contents. Preface. Introduction. Introduction to C Programming c11fptoc.fm Page vii Saturday, March 23, 2013 4:15 PM Preface xv 1 Introduction 1 1.1 1.2 1.3 1.4 1.5 Introduction The C Programming Language C Standard Library C++ and Other C-Based Languages Typical

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

C Fundamentals & Formatted Input/Output. adopted from KNK C Programming : A Modern Approach

C Fundamentals & Formatted Input/Output. adopted from KNK C Programming : A Modern Approach C Fundamentals & Formatted Input/Output adopted from KNK C Programming : A Modern Approach C Fundamentals 2 Program: Printing a Pun The file name doesn t matter, but the.c extension is often required.

More information

Overview of C. Basic Data Types Constants Variables Identifiers Keywords Basic I/O

Overview of C. Basic Data Types Constants Variables Identifiers Keywords Basic I/O Overview of C Basic Data Types Constants Variables Identifiers Keywords Basic I/O NOTE: There are six classes of tokens: identifiers, keywords, constants, string literals, operators, and other separators.

More information

UNIT IV INTRODUCTION TO C

UNIT IV INTRODUCTION TO C UNIT IV INTRODUCTION TO C 1. OVERVIEW OF C C is portable, structured programming language. It is robust, fast.extensible. It is used for complex programs. The root of all modern language is ALGOL (1960).

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

LEXICAL 2 CONVENTIONS

LEXICAL 2 CONVENTIONS LEXIAL 2 ONVENTIONS hapter SYS-ED/ OMPUTER EDUATION TEHNIQUES, IN. ++ Programming Lexical onventions Objectives You will learn: Operators. Punctuators. omments. Identifiers. Literals. SYS-ED \OMPUTER EDUATION

More information

The Design of C: A Rational Reconstruction: Part 2

The Design of C: A Rational Reconstruction: Part 2 The Design of C: A Rational Reconstruction: Part 2 1 Continued from previous lecture 2 Agenda Data Types Operators Statements I/O Facilities 3 Operators Issue: What kinds of operators should C have? Thought

More information

Java enum, casts, and others (Select portions of Chapters 4 & 5)

Java enum, casts, and others (Select portions of Chapters 4 & 5) Enum or enumerates types Java enum, casts, and others (Select portions of Chapters 4 & 5) Sharma Chakravarthy Information Technology Laboratory (IT Lab) Computer Science and Engineering Department The

More information

Informatics Ingeniería en Electrónica y Automática Industrial

Informatics Ingeniería en Electrónica y Automática Industrial Informatics Ingeniería en Electrónica y Automática Industrial Operators and expressions in C Operators and expressions in C Numerical expressions and operators Arithmetical operators Relational and logical

More information

Basics of Programming

Basics of Programming Unit 2 Basics of Programming Problem Analysis When we are going to develop any solution to the problem, we must fully understand the nature of the problem and what we want the program to do. Without the

More information

Gabriel Hugh Elkaim Spring CMPE 013/L: C Programming. CMPE 013/L: C Programming

Gabriel Hugh Elkaim Spring CMPE 013/L: C Programming. CMPE 013/L: C Programming 1 Literal Constants Definition A literal or a literal constant is a value, such as a number, character or string, which may be assigned to a variable or a constant. It may also be used directly as a function

More information

6.096 Introduction to C++ January (IAP) 2009

6.096 Introduction to C++ January (IAP) 2009 MIT OpenCourseWare http://ocw.mit.edu 6.096 Introduction to C++ January (IAP) 2009 For information about citing these materials or our Terms of Use, visit: http://ocw.mit.edu/terms. Welcome to 6.096 Lecture

More information

C Programming. Course Outline. C Programming. Code: MBD101. Duration: 10 Hours. Prerequisites:

C Programming. Course Outline. C Programming. Code: MBD101. Duration: 10 Hours. Prerequisites: C Programming Code: MBD101 Duration: 10 Hours Prerequisites: You are a computer science Professional/ graduate student You can execute Linux/UNIX commands You know how to use a text-editing tool You should

More information

Standard File Pointers

Standard File Pointers 1 Programming in C Standard File Pointers Assigned to console unless redirected Standard input = stdin Used by scan function Can be redirected: cmd < input-file Standard output = stdout Used by printf

More information

Console Input and Output

Console Input and Output Console Input and Output Hour 5 PObjectives

More information

C Concepts - I/O. Lecture 19 COP 3014 Fall November 29, 2017

C Concepts - I/O. Lecture 19 COP 3014 Fall November 29, 2017 C Concepts - I/O Lecture 19 COP 3014 Fall 2017 November 29, 2017 C vs. C++: Some important differences C has been around since around 1970 (or before) C++ was based on the C language While C is not actually

More information

Appendix. Grammar. A.1 Introduction. A.2 Keywords. There is no worse danger for a teacher than to teach words instead of things.

Appendix. Grammar. A.1 Introduction. A.2 Keywords. There is no worse danger for a teacher than to teach words instead of things. A Appendix Grammar There is no worse danger for a teacher than to teach words instead of things. Marc Block Introduction keywords lexical conventions programs expressions statements declarations declarators

More information

Full file at C How to Program, 6/e Multiple Choice Test Bank

Full file at   C How to Program, 6/e Multiple Choice Test Bank 2.1 Introduction 2.2 A Simple Program: Printing a Line of Text 2.1 Lines beginning with let the computer know that the rest of the line is a comment. (a) /* (b) ** (c) REM (d)

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

Fundamental of C programming. - Ompal Singh

Fundamental of C programming. - Ompal Singh Fundamental of C programming - Ompal Singh HISTORY OF C LANGUAGE IN 1960 ALGOL BY INTERNATIONAL COMMITTEE. IT WAS TOO GENERAL AND ABSTRUCT. IN 1963 CPL(COMBINED PROGRAMMING LANGUAGE) WAS DEVELOPED AT CAMBRIDGE

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

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

Object oriented programming. Instructor: Masoud Asghari Web page: Ch: 3

Object oriented programming. Instructor: Masoud Asghari Web page:   Ch: 3 Object oriented programming Instructor: Masoud Asghari Web page: http://www.masses.ir/lectures/oops2017sut Ch: 3 1 In this slide We follow: https://docs.oracle.com/javase/tutorial/index.html Trail: Learning

More information

Princeton University Computer Science 217: Introduction to Programming Systems The Design of C

Princeton University Computer Science 217: Introduction to Programming Systems The Design of C Princeton University Computer Science 217: Introduction to Programming Systems The Design of C C is quirky, flawed, and an enormous success. While accidents of history surely helped, it evidently satisfied

More information