A S H O R T I S H O V E R V I E W O F T H E A N S I C P R O G R A M M I N G L A N G U A G E

Size: px
Start display at page:

Download "A S H O R T I S H O V E R V I E W O F T H E A N S I C P R O G R A M M I N G L A N G U A G E"

Transcription

1 A S H O R T I S H O V E R V I E W O F T H E A N S I C P R O G R A M M I N G L A N G U A G E IDENTIFIERS Identifiers are names of variables, functions, defined types, structures and unions, enumeration constants, statement labels and preprocessor macros Identifiers are composed of alphanumeric characters, and _. Must start with a letter, and are case sensitive. ANSI C requires at least 31 characters to be significant. By convention, constants are in CAPITALS. External identifiers may be restricted to 6 significant characters only, and may be case insensitive DECLARATIONS All identifiers must be declared before they are used. Scope: region of a program over which that declaration is active functions have scope of the entire (multi-file) program. i.e. they are extern by default. identifiers declared within a function or block have block scope, or local scope statement labels have function scope all other identifiers have file scope Visibility: the declaration of an identifier is visible at some point in a program if the use of that identifier at that point causes it to be associated with that declaration. An identifier is usually visible throughout its scope, however it may be hidden if a second identifier of the same name but a more restricted scope is declared. Extent (or Lifetime): variables and functions have existence at run-time: they have storage allocated to them. The extent, or lifetime, of an object is the is the period of time for which storage is allocated. It has: static extent if storage is allocated when the program begins execution, and storage remains allocated until program terminates. All functions have static extent, as do variables declared outside any function. Variables declared inside blocks (functions) may have static extent (if they are declared static ). local (or automatic) extent if storage is allocated on entry to a block or function, and destroyed on exit from that block or function. If variable has an initialiser, it is reinitialised each time the block or function is entered. Formal parameters have local extent, and variables declared at the beginning of blocks may have local extent. auto variables have local extent. dynamic extent if storage is explicitly allocated and de-allocated by programmer. Library routines (e.g. malloc() and free()) are used to do this dynamic memory management.

2 Initial Value: variable declaration allocates storage for the variable, but does not initialise it good practice to initialise the variable when it is declared, so it is always initialised to something definite. also good practice to re-assign of change a value just before the variable is used! a static variable is initialised only once (when the program is loaded), and retains its value even if the program is executing outside the scope of the static variable. CONSTANTS Integer Character String 12 (decimal) 014 (octal - starts with zero) 0xC0 (hex) are the same integer. no binary integer type - easiest to use hex numbers instead. char const e.g.: 'R' has the value of the ASCII code for R (52 0x34 064). char consts can be represented as octal or hex escape sequences: \0x34 or \064 are both equivalent to 'R'. some non-printing ASCII constants are pre-defined. e.g.: \n is the ASCII new line character. string const e.g.: "a string". Automatically terminated by an ASCII null character '\0'. Floating point must contain decimal point and/or E. e.g.: 1.23 or 123E-4 Suffix of u or U denotes unsigned, l or L denotes long. e.g. 12L or L NAMED CONSTANTS It is extremely poor practice to use "magic numbers" in code. Use an editor to search for, and then destroy, any "magic numbers" that appear in your code. Replace them with named constants that are defined once, and collect all of the #defines in the same place (usually a header file). #define ARRAY_LENGTH 2500 #define BLOCK_SIZE 0x100 #define TRACK_SIZE (16*BLOCK_SIZE) #define ERROR_MESSAGE "** Error %d: %s. \n" VARIABLE DECLARATIONS All variables must be declared before they are used. Format of declaration is: <type qualifier> <storage class> <type> <name1>,..., <namen>; Default is signed auto int if variable declared in a function. A variable declared outside a function, including the main() function defaults to signed extern int

3 VARIABLE TYPES char char is usually 8-bit typically used to store one (7-bit or 8-bit) ASCII character char may be equivalent to either unsigned char or signed char, or a mixture of both (pseudo-unsigned), depending on implementation. Beware! signed char signed char is usually 8-bit signed integer: -128 to +127 (-2 7 to ) unsigned char is usually an unsigned 8-bit number: 0 to 255 (0 to 2 8-1) short also called short int or signed short or signed short int signed integer, size is architecture dependent. on 16-bit machine is -32,768 to +32,767 (-2 15 to ) unsigned short also called unsigned short int unsigned integer, size is architecture dependent. on 16-bit machine is 0 to 65,535 (0 to ) int also called signed int or signed default variable type is int signed integer, size is architecture dependent. on 16-bit machine is -32,768 to +32,767 (-2 15 to ) unsigned int also called unsigned unsigned integer, size is architecture dependent. on 16-bit machine is 0 to 65,535 (0 to ) long also called long int or signed long or signed long int signed integer, size is architecture dependent. on 16-bit machine is usually 32-bit -2,147,483,648 to +2,147,483,647 unsigned long also called unsigned long int signed integer, size is architecture dependent. on 16-bit machine is 32-bit 0 to 4,294,967,295 (0 to ) ANSI C specification requires only that a char is at least 8 bits, a short or an int are at least 16 bits, and a long is at least 32 bits. The ranges of permissible values of the various integer types in a given implementation are defined in limits.h. float floating point number, often 4-byte: 3.4 E ± 38 ( 7 decimal digits) double floating point number, often 8-byte: 1.7 E ±308 (15 decimal digits)

4 long double not ANSI C type, but C++ type only! floating point number, 80 bits: 3.4E+4932 to -1.1E-4932 (19 decimal digits) The form of floating point types is not specified, nor are they even required to be different! The ranges of permissible values of floating point types in a given implementation are defined in float.h. void is a type used to explicitly specify an empty set, or no value. POINTER TYPES For any type T, a type pointer to T may be formed. A variable of type pointer to T holds the address in memory of an object of type T. A pointer may point to a variable or a function. Some example declarations: char * ptr; ptr is a pointer to an object of type char int (* fp)(char); fp is pointer to function with char argument that returns int double (* ap)[]; ap is a pointer to an array of double Note that some function declarations look a bit like pointer declarations... int * tool(char); tool is function with char argument returning a pointer to int int * sally[]; sally is an array of pointers to int A generic pointer type is defined. This generic pointer can be cast to a pointer to an object of any type. In ANSI C, the generic pointer type is void * (read this as pointer to void). A null pointer explicitly points to no object or function. The standard header files stddef.h contains the definition of the null pointer, NULL. Since the value of NULL is implementation dependent, one should test for equality to NULL, rather than to 0 or 0L or (void *) 0. It is good practice to ensure that all pointers have the value NULL when they are not pointing to a valid object or function. ARRAY TYPES <type> <name>[m][n] is an m-by-n array. For example, int harry[2][3], sally[4]; /* harry is 2x3, sally is 1x4 */ arrays may have any number of dimensions. e.g. int hyper[8][2][10][6][13]; elements are numbered from zero. address of harry is the same as &harry[0][0], and also the same as harry subscripting is done with pointer arithmetic. Thus, sally[i] is the same as *(sally + i) array initialisation: int harry[2][3] = 3, 2, 1, 4, 27, -11 ; int squares[] = 1, 4, 9, 16, 25; char message[] = "Braces may be omitted";

5 STORAGE CLASS SPECIFIERS auto static extern variables are local to the block (includes function) in which they are declared. memory is allocated when variable is used, released when function terminates i.e. passed through the stack. Efficient use of memory, but function "forgets" between invocations. i.e. variable has local (automatic) extent. variable retains its value between invocations, as it is allocated a fixed address in RAM. The variable has static extent. if declared within a function, scope is that function. i.e. "private" to the function. if static variable declared outside all functions, scope is file in which it is declared. i.e. global inside file, but not visible outside file - a module variable. scope of static function is file in which declared: the name of the function is not exported to the linker. i.e. a static function is "private" to the file. extern functions and variables have external linkage: their names are exported to the linker, so that they are visible outside the present file. extern objects have static extent variables declared outside all functions are extern by default. local variables with the same name take precedence within their scope. extern function is defined outside of the present file. Scope is global. register use a CPU register to store the value, if possible, to give fast access to a variable. TYPE QUALIFIERS const object is nonmodifiable. Some compilers may place the object in ROM. volatile object can be modified by something outside the scope of the program, such as an external hardware event. Instructs the compiler not to optimise a volatile variable across sequence points. DEFINED AND COMPOSITE TYPES typedef used to define new data types in terms of those already defined. Does not allocate storage. extremely useful for building portability into code!! For example, typedef unsigned char * prompt_t; defines a new data type, prompt_t to be a pointer to unsigned char. Then, prompt_t user_prompt; declares a new variable user_prompt of type prompt_t.

6 struct a structure is a derived data type consisting of one or more named members of the same or different data types. For example, struct material_s /* definition */ float density; float modulus; float yield_strength; ; defines a new structure. material_s is the structure tag. struct material_s steel; /* declaration */ declares steel to be an instance of a material_s structure. steel.modulus = 207.0E+09; /* use */ selects the modulus component of steel and assigns a value to it. component selection can also be done through a pointer to a structure: struct material_s * ptr_steel; ptr_steel = &steel; ptr_steel->modulus = 207.0E+09; union a union is a derived data type capable of containing, at different times, any one of several different data types. It is like a structure big enough to contain any of the members - only one member can be stored at any time. For example, union mixed_u /* definition */ char c; int i; long l; ; union mixed_u x; /* declaration */ x.c = 27; /* use this */ x.l = ; /* OR this!! */ components of unions are selected in the same way as components of structures. enum enumerated types have values that can range only over a set of named (int) constants called enumerators. For example. enum state_e false, true; /* definition */ enum state_e sleeping; /* declaration */ sleeping = false; /* use */

7 Enumerated types take sequential integer values starting from zero. In the example above, false==0 and true==1. Alternatively, can initialise values: enum colour_e red = 2, green = 4, blue = 8; BITFIELDS Structures used in machine-dependent programs that must force a data structure that corresponds exactly to fixed hardware features. Bit fields may be of type int, signed int or unsigned int. "Padding" may be required to create holes. Ordering of bit packing will depend on whether the target computer is a "big endian" or a "little endian". Bitfields are therefore likely to be non-portable. #define SET 1 #define CLEAR 0 typedef struct unsigned int bit0: 1; /* low byte */ unsigned int bit1: 1; unsigned int bit2: 1; unsigned int bit3: 1; unsigned int bit4: 1; unsigned int bit5: 1; unsigned int bit6: 1; unsigned int bit7: 1; unsigned int odd_byte: 8; /* pad out to 16 bits */ port_even_b; struct port_even_b * ad_command = ((struct port_even_b *) 0x02); ad_command->bit4 = SET;

8 OPERATORS arithmetic + - * / Integer division truncates. e.g.: 99/100 == 0; 5/3 == 1; assignment = Can use multiple assignment. e.g.: a = b = c = 0; Short form of assignment: e.g.: a += b; is the same as a = a + b; increment ++ increment -- decrement Pre-increment is ++b; Post-increment is b++; increment b, then use b use b, then increment it bitwise ~ NOT & AND OR ^ XOR Bitwise operators are useful for setting and testing bits. Some examples: #define EMPTY #define CTS 0x04 0x20 flags = (EMPTY CTS); /* sets EMPTY, CTS bits */ flags &= ~(EMPTY CTS); /* resets them */ flags ^= (EMPTY); /* changes state of EMPTY */ if!(flags & (EMPTY CTS)) /* true if both bits set */ shift i << j Shift i left by j bits i >> j Shift i right by j bits If i is unsigned, or signed and positive, zeros are shifted in to replace bits shifted out (logical shift). If i is signed and negative, some compilers do arithmetic shift (preserve the sign bit), some do logical shift. relational > greater than < less than >= greater than or equal to <= less than or equal to == equal to!= not equal to logical (...) &&!(...) (...) and NOT(...) connective (...) (...) (...) or (...) an expression which is TRUE will evaluate to 1 an expression which is NON-ZERO is interpreted as TRUE

9 useful to do #define FALSE 0 #define TRUE 1 sizeof sizeof(object) returns the size of the argument measured in memory storage units (usually bytes). The type returned by sizeof() is size_t, defined in stddef.h. MIXED-TYPE EXPRESSIONS legal but potentially dangerous: compiler automatically performs type conversion so all variables in expression are of same type before expression is evaluated. Can cause unexpected results if you don't think like a compiler!! preferred types are starred, below. In a mixed-type expression, non-preferred types are first promoted to a preferred type, then all are promoted to the highest type. double float long unsigned int int char automatic conversion across assignment: value on RS converted to type on LS. For example: an_int = a_char; is OK a_char = an_int; will (probably) truncate high byte of an_int an_int = a_float; is suspect, if a_float > 32,767 a "cast" is used to explicitly change a variable's type. The classical example is casting a generic pointer during dynamic memory allocation. The library function malloc() returns void *. material_s * ptr_zinc = (struct material_s *) malloc(); This statement only allocates memory and initialises the pointer: the memory is not initialised. Another example is the use of a cast in defining the type stored at an absolute address: #define SBUF (* (unsigned char *)(0x07)) if you have to use lots of casts, there may be something wrong with choice of variable types.

10 STATEMENTS simple statement e.g.: x = a + b; /* Note semicolon! */ compound statement or sequential structure is created by using braces to group simple statements into a block. e.g.: x = a + b; /* This is a comment. */ b = sin(x); /* Comments can NOT be nested */ the statements within the braces... constitute a block. FLOW CONTROL CONSTRUCTS In the following constructs, <statement> can be a single statement or construct, or a block of statements or constructs. <expression> is anything which evaluates to either TRUE or FALSE. These constructs allow for the direct implementation of structured code. if else construct if (<expression>) <statement1>; else <statement2>; the else is optional multiple if-else constructs may be used: if (<expression1>) <statement1>; else if (<expression2>) <statement2>; else if (<expression3>) <statement3>; else <statement4>;

11 Conditional Expression r = <expression>? <statement1> : <statement2>; is equivalent to if (<expression>) /* if TRUE or!= 0 */ r = <statement1>; else r = <statement2>; switch construct switch (<integer expression>) case <integer constant1>: case <integer constant2>: case <integer constant3>: default: <integer constant> should be set up in a #define preprocessor directive, or as an enumerated type. For example, #define RESET 3 /* or... */ enum COMMAND_E INIT, GO, STOP, RESET, EXIT; each group of <statements> will usually have to end with break; The break statement causes execution of the smallest enclosing while, do, for or switch to terminate. the default: block is optional, but is good practice. while construct while(<expression>) /* Can have zero passes */ an infinite loop is often written while (TRUE)

12 do while construct do while (<expression>); /* Minimum of one pass */ for construct for (<loop initiation>; <loop test>; <loop action>) behaves exactly the same as <loop initiation>; while (<loop test>) <loop action>; an infinite loop is also commonly written for (;;) /* statements... */ break, continue and goto execution of a break statement causes the transfer of control to the first statement following the innermost enclosing while, do or for loop, or switch statement. execution of a continue statement causes the transfer of control to the beginning of the innermost enclosing while, do, or for loop statement. Execution of the affected loop statement may continue following re-evaluation of the loop continuation condition test. a continue statement has no interaction with an enclosing switch statement. a goto statement may be used to transfer execution to any statement within a function: /* some statements */ goto find_the_label; /* lots of statements... */ find_the_label: /* more statements... /*

13 Use goto with extreme care, and only when really necessary. It can lead to unreadable "spaghetti" code. In particular, never use a goto to branch into the body of an if, a switch, a for or a block from outside the block. it is far better style to use break, continue and return statements in place of goto. FUNCTIONS Function is block of statements invoked by a single call. Each function should be declared before it is used. This is nor required by ANSI C, but is strongly recommended, as it allows the compiler to perform type checking. The "prototype" form of a declaration is <type qualifier> <storage class> <type> <name> (<argument list>); where <argument list> is of the form <<type qualifier> <storage class> <type> <name1>, <type qualifier> <storage class> <type> <name2>,..., <type qualifier> <storage class> <type> <namen>> Some examples of the prototype form of function declarations: char func(unsigned); func is a function with one unsigned argument that returns a char long * junk(double, float); junk is a function with 2 arguments - a double and a float that returns a pointer to long void monk(float *, long); monk is a function with 2 arguments - a pointer to float and a long that returns nothing double * punk(void) punk is a function with no arguments that returns a pointer to double Note that some pointer declarations look a bit like function declarations... int (* fp)(void); fp is pointer to function with no arguments that returns int void (* fp)(void); fp is pointer to function with no arguments that returns nothing Each function must be defined (see below) before it is invoked. Format of function invocation (call) is <function name> (<arguments>); Parenthesis must be present even if the function has no arguments. Arguments are passed by value. That is, copies of the arguments are made, and the copies are transferred to the function. See "call by reference", following. When a function appears in an expression, its value is the value returned by the function. Note that multiple calls of the same function within an expression are not guaranteed!

14 The default return type of a function is extern signed int. A function with the return type void must not have a return statement. Function definition Consists of declarations and statements that make up the function. Format of a function definition is: <type qualifier> <storage class> <type> <name> (<argument list>) <local variable declarations>; return (<expression>); /* omit if function returns void */ where, for the prototype form of a definition, <argument list> is of the form <<type qualifier> <storage class> <type> <name1>, <type qualifier> <storage class> <type> <name2>,..., <type qualifier> <storage class> <type> <namen>> Function definitions may not be nested. A function that can have a second copy of itself invoked before the first copy has terminated is called reentrant. A recursive function must also be reentrant. A function that uses only auto variables will be reentrant. Any functions invoked by an interrupt must be reentrant. Note that not all compilers produce reentrant code! POINTERS [Simple Usage See also miscellaneous examples given previously] A pointer is a variable which stores the address of another variable. If the pointer variable ptr contains the address of another variable var, then ptr is said to point to var. Pointer declaration Pointers are declared as <type> * <name>; /* the pointer type is <type> * */ for example: unsigned char * ptr; /* ptr points to (is the address of) an */ /* unsigned char. *ptr is the value of */ /* the unsigned char pointed to by ptr */

15 Pointer initialisation ptr = &var; /* ptr assigned the address of var */ ptr = "string const"; /* compiler allocates storage for string */ /* ptr assigned address of first character */ Pointer indirection unsigned char * ptr; /* declare ptr a pointer to unsigned char. */ /* *ptr is the unsigned char variable, */ /* which is not yet initialised. */ unsigned char c, d; unsigned char * ptr; c = 55; ptr = &c; /* ptr is the address of c */ d = *ptr; /* d = value of variable pointed to by ptr */ ++*ptr; /* Same as ++c */ Common usage of pointers is when a function must change values of arguments ("call by reference"). For example: void swap(int *, int *); /* prototype function declaration */ int first = 23, /* declare and initialise variables */ second = 44; swap (&first, &second); /* invocation - will swap values */ void swap(int* a, int* b) /* prototype style function definition */ int temp; temp = *a; *a = *b; *b = temp; Pointer (i.e. address) arithmetic Valid operations with pointers are add integer to pointer subtract integer from pointer increment/decrement pointer compare two pointers using relational operators subtract two pointers which point to elements of the same array Pointer operations are automatically scaled to account for the differing sizes of variables of different type.

16 The type of the result of subtracting one pointer from another is architecture dependent. It is of type ptrdiff_t, defined in stddef.h. Pointer arithmetic with arrays int a[10]; /* Array of 10 ints; a is a pointer to a[0] */ So, *(a+2) is the same as a[2] When an array is passed to a function, only the pointer to the array is actually passed. Thus, arrays are always passed by address, and the function can alter the values of array elements. DYNAMIC MEMORY MANAGEMENT the storage allocation facility provides examples of standard library functions which allow the program to allocate a region of memory from the "heap" (unallocated RAM), and deallocate it when no longer required. memory allocation functions return a generic pointer (void *). The user may then use a cast to convert the pointer to another pointer type. malloc() alocates storage for one object of size size, as determined by sizeof(size). The memory is not initialised. If the memory cannot be allocated, a NULL pointer is returned. For example, a function to allocate (memory for) a new object of type object_t : object_t * object_t * new_object_t(void) objectptr; objectptr = (object_t *) malloc(sizeof(object_t)); if (objectptr == NULL) printf("new_object: out of memory!\n"); return (objectptr); free() deallocates memory previously allocated by malloc(), calloc() or realloc(). once memory has been deallocated, it is an error to use this deallocated memory. realloc() can be used to increase or decrease the size of a region of previously allocated memory. If the size is increased, any information previously stored may be retained (if realloc() returns the same pointer). If realloc() is called to reallocate a region to size zero, the action is the same as free().

17 PREPROCESSOR DIRECTIVES The preprocessor operates on the source file before it is parsed by the compiler. Preprocessor directives tell the preprocessor what to do. Common directives include: #define defines an identifier to be equal to a token sequence. For example: #define PROMPT '>' /* defined constants */ #define PIO_C_A 0x0021 #define IO_PORT3 (* (unsigned char *) (0x1FFE)) /* contents of absolute address */ #define stop_m() (outp(pio_c_a, HALT);) /* macro definition */ #define square(x) ((x)*(x)) /* brackets for correct macro expansion! */ you should have NO numerals ("magic numbers") in source code use a text editor to search for them. Use #defined constants and collect them together in a header file. #ifdef can test to see if a macro is defined (i.e. non-zero). Useful for debugging instrumentation: #ifdef DEBUG /* debugging statements... */ #endif #include causes the entire contents of a file to be included in place of the include statement. For example: # include <filename> /* system file */ # include "filename" /* user's file */ to ensure that a header file is included only once, do #if!defined(header_name) #define HEADER_NAME... /* body of header file */ #endif /*!defined(header_name) */

18 That's all for a shortish introduction. Two excellent general references on the C language are Kernighan, B.W. and Ritchie, D.M. The C Programming Language. 2ed, Prentice Hall, Englewood Cliffs NJ, c Make sure to get the 2nd (ANSI) edition! Dennis Ritchie wrote the C language. Harbison, S.P. and Steele, G.L. C: A Reference Manual. Prentice Hall, Englewood Cliffs NJ, A nice book on program construction is McConnell, S.J. Code Complete. Microsoft Press, Thanks to Chris Bujor for reviewing this document, and for his many helpful suggestions. Any errors or omissions remaining are, of course, my responsibility. DCR 15 July, File: C.DOC Created: DCR, 23/4/94 Saved: 15/07/ :12 PM Printed: 29/04/2002 2:16 PM

19 Could add: Console I/O printf() and scanf() file I/O

Review of the C Programming Language for Principles of Operating Systems

Review of the C Programming Language for Principles of Operating Systems Review of the C Programming Language for Principles of Operating Systems Prof. James L. Frankel Harvard University Version of 7:26 PM 4-Sep-2018 Copyright 2018, 2016, 2015 James L. Frankel. All rights

More information

Review of the C Programming Language

Review of the C Programming Language Review of the C Programming Language Prof. James L. Frankel Harvard University Version of 11:55 AM 22-Apr-2018 Copyright 2018, 2016, 2015 James L. Frankel. All rights reserved. Reference Manual for the

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

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

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

BLM2031 Structured Programming. Zeyneb KURT

BLM2031 Structured Programming. Zeyneb KURT BLM2031 Structured Programming Zeyneb KURT 1 Contact Contact info office : D-219 e-mail zeynebkurt@gmail.com, zeyneb@ce.yildiz.edu.tr When to contact e-mail first, take an appointment What to expect help

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

C Programming SYLLABUS COVERAGE SYLLABUS IN DETAILS

C Programming SYLLABUS COVERAGE SYLLABUS IN DETAILS C Programming C SYLLABUS COVERAGE Introduction to Programming Fundamentals in C Operators and Expressions Data types Input-Output Library Functions Control statements Function Storage class Pointer Pointer

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

Tokens, Expressions and Control Structures

Tokens, Expressions and Control Structures 3 Tokens, Expressions and Control Structures Tokens Keywords Identifiers Data types User-defined types Derived types Symbolic constants Declaration of variables Initialization Reference variables Type

More information

IMPORTANT QUESTIONS IN C FOR THE INTERVIEW

IMPORTANT QUESTIONS IN C FOR THE INTERVIEW IMPORTANT QUESTIONS IN C FOR THE INTERVIEW 1. What is a header file? Header file is a simple text file which contains prototypes of all in-built functions, predefined variables and symbolic constants.

More information

P.G.TRB - COMPUTER SCIENCE. c) data processing language d) none of the above

P.G.TRB - COMPUTER SCIENCE. c) data processing language d) none of the above P.G.TRB - COMPUTER SCIENCE Total Marks : 50 Time : 30 Minutes 1. C was primarily developed as a a)systems programming language b) general purpose language c) data processing language d) none of the above

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

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

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

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

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

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

EL6483: Brief Overview of C Programming Language

EL6483: Brief Overview of C Programming Language EL6483: Brief Overview of C Programming Language EL6483 Spring 2016 EL6483 EL6483: Brief Overview of C Programming Language Spring 2016 1 / 30 Preprocessor macros, Syntax for comments Macro definitions

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

DEPARTMENT OF MATHS, MJ COLLEGE

DEPARTMENT OF MATHS, MJ COLLEGE T. Y. B.Sc. Mathematics MTH- 356 (A) : Programming in C Unit 1 : Basic Concepts Syllabus : Introduction, Character set, C token, Keywords, Constants, Variables, Data types, Symbolic constants, Over flow,

More information

CS201 - Introduction to Programming Glossary By

CS201 - Introduction to Programming Glossary By CS201 - Introduction to Programming Glossary By #include : The #include directive instructs the preprocessor to read and include a file into a source code file. The file name is typically enclosed with

More information

C LANGUAGE AND ITS DIFFERENT TYPES OF FUNCTIONS

C LANGUAGE AND ITS DIFFERENT TYPES OF FUNCTIONS C LANGUAGE AND ITS DIFFERENT TYPES OF FUNCTIONS Manish Dronacharya College Of Engineering, Maharishi Dayanand University, Gurgaon, Haryana, India III. Abstract- C Language History: The C programming language

More information

C Review. MaxMSP Developers Workshop Summer 2009 CNMAT

C Review. MaxMSP Developers Workshop Summer 2009 CNMAT C Review MaxMSP Developers Workshop Summer 2009 CNMAT C Syntax Program control (loops, branches): Function calls Math: +, -, *, /, ++, -- Variables, types, structures, assignment Pointers and memory (***

More information

About Codefrux While the current trends around the world are based on the internet, mobile and its applications, we try to make the most out of it. As for us, we are a well established IT professionals

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

CprE 288 Introduction to Embedded Systems Exam 1 Review. 1

CprE 288 Introduction to Embedded Systems Exam 1 Review.  1 CprE 288 Introduction to Embedded Systems Exam 1 Review http://class.ece.iastate.edu/cpre288 1 Overview of Today s Lecture Announcements Exam 1 Review http://class.ece.iastate.edu/cpre288 2 Announcements

More information

CENG 447/547 Embedded and Real-Time Systems. Review of C coding and Soft Eng Concepts

CENG 447/547 Embedded and Real-Time Systems. Review of C coding and Soft Eng Concepts CENG 447/547 Embedded and Real-Time Systems Review of C coding and Soft Eng Concepts Recall (C-style coding syntax) ; - Indicate the end of an expression {} - Used to delineate when a sequence of elements

More information

The Waite Group's. New. Primer Plus. Second Edition. Mitchell Waite and Stephen Prata SAMS

The Waite Group's. New. Primer Plus. Second Edition. Mitchell Waite and Stephen Prata SAMS The Waite Group's New Primer Plus Second Edition Mitchell Waite and Stephen Prata SAMS PUBLISHING A Division of Prentice Hall Computer Publishing 11711 North College, Carmel, Indiana 46032 USA Contents

More information

Short Notes of CS201

Short Notes of CS201 #includes: Short Notes of CS201 The #include directive instructs the preprocessor to read and include a file into a source code file. The file name is typically enclosed with < and > if the file is a system

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

Binghamton University. CS-211 Fall Syntax. What the Compiler needs to understand your program

Binghamton University. CS-211 Fall Syntax. What the Compiler needs to understand your program Syntax What the Compiler needs to understand your program 1 Pre-Processing Any line that starts with # is a pre-processor directive Pre-processor consumes that entire line Possibly replacing it with other

More information

CS Programming In C

CS Programming In C CS 24000 - Programming In C Week Two: Basic C Program Organization and Data Types Zhiyuan Li Department of Computer Science Purdue University, USA 2 int main() { } return 0; The Simplest C Program C programs

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

C-LANGUAGE CURRICULAM

C-LANGUAGE CURRICULAM C-LANGUAGE CURRICULAM Duration: 2 Months. 1. Introducing C 1.1 History of C Origin Standardization C-Based Languages 1.2 Strengths and Weaknesses Of C Strengths Weaknesses Effective Use of C 2. C Fundamentals

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

Basic Types, Variables, Literals, Constants

Basic Types, Variables, Literals, Constants Basic Types, Variables, Literals, Constants What is in a Word? A byte is the basic addressable unit of memory in RAM Typically it is 8 bits (octet) But some machines had 7, or 9, or... A word is the basic

More information

Character Set. The character set of C represents alphabet, digit or any symbol used to represent information. Digits 0, 1, 2, 3, 9

Character Set. The character set of C represents alphabet, digit or any symbol used to represent information. Digits 0, 1, 2, 3, 9 Character Set The character set of C represents alphabet, digit or any symbol used to represent information. Types Uppercase Alphabets Lowercase Alphabets Character Set A, B, C, Y, Z a, b, c, y, z Digits

More information

CS201 Some Important Definitions

CS201 Some Important Definitions CS201 Some Important Definitions For Viva Preparation 1. What is a program? A program is a precise sequence of steps to solve a particular problem. 2. What is a class? We write a C++ program using data

More information

Topic 6: A Quick Intro To C. Reading. "goto Considered Harmful" History

Topic 6: A Quick Intro To C. Reading. goto Considered Harmful History Topic 6: A Quick Intro To C Reading Assumption: All of you know basic Java. Much of C syntax is the same. Also: Some of you have used C or C++. Goal for this topic: you can write & run a simple C program

More information

Programming Fundamentals (CS 302 ) Dr. Ihsan Ullah. Lecturer Department of Computer Science & IT University of Balochistan

Programming Fundamentals (CS 302 ) Dr. Ihsan Ullah. Lecturer Department of Computer Science & IT University of Balochistan Programming Fundamentals (CS 302 ) Dr. Ihsan Ullah Lecturer Department of Computer Science & IT University of Balochistan 1 Outline p Introduction p Program development p C language and beginning with

More information

Structure of this course. C and C++ Past Exam Questions. Text books

Structure of this course. C and C++ Past Exam Questions. Text books Structure of this course C and C++ 1. Types Variables Expressions & Statements Alastair R. Beresford University of Cambridge Lent Term 2008 Programming in C: types, variables, expressions & statements

More information

DETAILED SYLLABUS INTRODUCTION TO C LANGUAGE

DETAILED SYLLABUS INTRODUCTION TO C LANGUAGE COURSE TITLE C LANGUAGE DETAILED SYLLABUS SR.NO NAME OF CHAPTERS & DETAILS HOURS ALLOTTED 1 INTRODUCTION TO C LANGUAGE About C Language Advantages of C Language Disadvantages of C Language A Sample Program

More information

ME 461 C review Session Fall 2009 S. Keres

ME 461 C review Session Fall 2009 S. Keres ME 461 C review Session Fall 2009 S. Keres DISCLAIMER: These notes are in no way intended to be a complete reference for the C programming material you will need for the class. They are intended to help

More information

edunepal_info

edunepal_info facebook.com/edunepal.info @ edunepal_info C interview questions (1 125) C interview questions are given with the answers in this website. We have given C interview questions faced by freshers and experienced

More information

Rule 1-3: Use white space to break a function into paragraphs. Rule 1-5: Avoid very long statements. Use multiple shorter statements instead.

Rule 1-3: Use white space to break a function into paragraphs. Rule 1-5: Avoid very long statements. Use multiple shorter statements instead. Chapter 9: Rules Chapter 1:Style and Program Organization Rule 1-1: Organize programs for readability, just as you would expect an author to organize a book. Rule 1-2: Divide each module up into a public

More information

INTRODUCTION 1 AND REVIEW

INTRODUCTION 1 AND REVIEW INTRODUTION 1 AND REVIEW hapter SYS-ED/ OMPUTER EDUATION TEHNIQUES, IN. Programming: Advanced Objectives You will learn: Program structure. Program statements. Datatypes. Pointers. Arrays. Structures.

More information

MISRA-C:2012 Standards Model Summary for C / C++

MISRA-C:2012 Standards Model Summary for C / C++ Version 9.7.1 Copyright 2017 Ltd. MISRA-C:2012 s Model Summary for C / C++ The tool suite is developed and certified to BS EN ISO 9001:2000 and SGS-TÜV Saar. This information is applicable to version 9.7.1

More information

Why Pointers. Pointers. Pointer Declaration. Two Pointer Operators. What Are Pointers? Memory address POINTERVariable Contents ...

Why Pointers. Pointers. Pointer Declaration. Two Pointer Operators. What Are Pointers? Memory address POINTERVariable Contents ... Why Pointers Pointers They provide the means by which functions can modify arguments in the calling function. They support dynamic memory allocation. They provide support for dynamic data structures, such

More information

Programming, numerics and optimization

Programming, numerics and optimization Programming, numerics and optimization Lecture A-2: Programming basics II Łukasz Jankowski ljank@ippt.pan.pl Institute of Fundamental Technological Research Room 4.32, Phone +22.8261281 ext. 428 March

More information

Expressions and Data Types CSC 121 Spring 2015 Howard Rosenthal

Expressions and Data Types CSC 121 Spring 2015 Howard Rosenthal Expressions and Data Types CSC 121 Spring 2015 Howard Rosenthal Lesson Goals Understand the basic constructs of a Java Program Understand how to use basic identifiers Understand simple Java data types

More information

C Language, Token, Keywords, Constant, variable

C Language, Token, Keywords, Constant, variable C Language, Token, Keywords, Constant, variable A language written by Brian Kernighan and Dennis Ritchie. This was to be the language that UNIX was written in to become the first "portable" language. C

More information

Motor Industry Software Reliability Association (MISRA) C:2012 Standard Mapping of MISRA C:2012 items to Goanna checks

Motor Industry Software Reliability Association (MISRA) C:2012 Standard Mapping of MISRA C:2012 items to Goanna checks Goanna 3.3.2 Standards Data Sheet for MISRA C:2012 misrac2012-datasheet.pdf Motor Industry Software Reliability Association (MISRA) C:2012 Standard Mapping of MISRA C:2012 items to Goanna checks The following

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

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

CODE TIME TECHNOLOGIES. Abassi RTOS MISRA-C:2004. Compliance Report

CODE TIME TECHNOLOGIES. Abassi RTOS MISRA-C:2004. Compliance Report CODE TIME TECHNOLOGIES Abassi RTOS MISRA-C:2004 Compliance Report Copyright Information This document is copyright Code Time Technologies Inc. 2012. All rights reserved. No part of this document may be

More information

from Appendix B: Some C Essentials

from Appendix B: Some C Essentials from Appendix B: Some C Essentials tw rev. 22.9.16 If you use or reference these slides or the associated textbook, please cite the original authors work as follows: Toulson, R. & Wilmshurst, T. (2016).

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

Programming in C and C++

Programming in C and C++ Programming in C and C++ 1. Types Variables Expressions & Statements Dr. Anil Madhavapeddy University of Cambridge (based on previous years thanks to Alan Mycroft, Alastair Beresford and Andrew Moore)

More information

Variables and literals

Variables and literals Demo lecture slides Although I will not usually give slides for demo lectures, the first two demo lectures involve practice with things which you should really know from G51PRG Since I covered much of

More information

(heavily based on last year s notes (Andrew Moore) with thanks to Alastair R. Beresford. 1. Types Variables Expressions & Statements 2/23

(heavily based on last year s notes (Andrew Moore) with thanks to Alastair R. Beresford. 1. Types Variables Expressions & Statements 2/23 Structure of this course Programming in C: types, variables, expressions & statements functions, compilation, pre-processor pointers, structures extended examples, tick hints n tips Programming in C++:

More information

Room 3P16 Telephone: extension ~irjohnson/uqc146s1.html

Room 3P16 Telephone: extension ~irjohnson/uqc146s1.html UQC146S1 Introductory Image Processing in C Ian Johnson Room 3P16 Telephone: extension 3167 Email: Ian.Johnson@uwe.ac.uk http://www.csm.uwe.ac.uk/ ~irjohnson/uqc146s1.html Ian Johnson 1 UQC146S1 What is

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

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

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

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

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

I BCA[ ] SEMESTER I CORE: C PROGRAMMING - 106A Multiple Choice Questions.

I BCA[ ] SEMESTER I CORE: C PROGRAMMING - 106A Multiple Choice Questions. 1 of 22 8/4/2018, 4:03 PM Dr.G.R.Damodaran College of Science (Autonomous, affiliated to the Bharathiar University, recognized by the UGC)Reaccredited at the 'A' Grade Level by the NAAC and ISO 9001:2008

More information

Chapter 1. C Pocket Reference

Chapter 1. C Pocket Reference Chapter 1. C Pocket Reference Section 1.1. Introduction Section 1.2. Fundamentals Section 1.3. Basic Types Section 1.4. Constants Section 1.5. Expressions and Operators Section 1.6. Type Conversions Section

More information

Lecture 03 Bits, Bytes and Data Types

Lecture 03 Bits, Bytes and Data Types Lecture 03 Bits, Bytes and Data Types Computer Languages A computer language is a language that is used to communicate with a machine. Like all languages, computer languages have syntax (form) and semantics

More information

Language Design COMS W4115. Prof. Stephen A. Edwards Spring 2003 Columbia University Department of Computer Science

Language Design COMS W4115. Prof. Stephen A. Edwards Spring 2003 Columbia University Department of Computer Science Language Design COMS W4115 Prof. Stephen A. Edwards Spring 2003 Columbia University Department of Computer Science Language Design Issues Syntax: how programs look Names and reserved words Instruction

More information

Single-pass Static Semantic Check for Efficient Translation in YAPL

Single-pass Static Semantic Check for Efficient Translation in YAPL Single-pass Static Semantic Check for Efficient Translation in YAPL Zafiris Karaiskos, Panajotis Katsaros and Constantine Lazos Department of Informatics, Aristotle University Thessaloniki, 54124, Greece

More information

Holtek C and ANSI C Feature Comparison User s Guide

Holtek C and ANSI C Feature Comparison User s Guide Holtek C and ANSI C Feature Comparison User s Guide July 2009 Copyright 2009 by HOLTEK SEMICONDUCTOR INC. All rights reserved. Printed in Taiwan. No part of this publication may be reproduced, stored in

More information

We do not teach programming

We do not teach programming We do not teach programming We do not teach C Take a course Read a book The C Programming Language, Kernighan, Richie Georgios Georgiadis Negin F.Nejad This is a brief tutorial on C s traps and pitfalls

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

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

Subject: PROBLEM SOLVING THROUGH C Time: 3 Hours Max. Marks: 100

Subject: PROBLEM SOLVING THROUGH C Time: 3 Hours Max. Marks: 100 Code: DC-05 Subject: PROBLEM SOLVING THROUGH C Time: 3 Hours Max. Marks: 100 NOTE: There are 11 Questions in all. Question 1 is compulsory and carries 16 marks. Answer to Q. 1. must be written in the space

More information

XSEDE Scholars Program Introduction to C Programming. John Lockman III June 7 th, 2012

XSEDE Scholars Program Introduction to C Programming. John Lockman III June 7 th, 2012 XSEDE Scholars Program Introduction to C Programming John Lockman III June 7 th, 2012 Homework 1 Problem 1 Find the error in the following code #include int main(){ } printf(find the error!\n");

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

COMP322 - Introduction to C++ Lecture 02 - Basics of C++

COMP322 - Introduction to C++ Lecture 02 - Basics of C++ COMP322 - Introduction to C++ Lecture 02 - Basics of C++ School of Computer Science 16 January 2012 C++ basics - Arithmetic operators Where possible, C++ will automatically convert among the basic types.

More information

Expressions and Data Types CSC 121 Fall 2015 Howard Rosenthal

Expressions and Data Types CSC 121 Fall 2015 Howard Rosenthal Expressions and Data Types CSC 121 Fall 2015 Howard Rosenthal Lesson Goals Understand the basic constructs of a Java Program Understand how to use basic identifiers Understand simple Java data types and

More information

VARIABLES AND CONSTANTS

VARIABLES AND CONSTANTS UNIT 3 Structure VARIABLES AND CONSTANTS Variables and Constants 3.0 Introduction 3.1 Objectives 3.2 Character Set 3.3 Identifiers and Keywords 3.3.1 Rules for Forming Identifiers 3.3.2 Keywords 3.4 Data

More information

Topic 6: A Quick Intro To C

Topic 6: A Quick Intro To C Topic 6: A Quick Intro To C Assumption: All of you know Java. Much of C syntax is the same. Also: Many of you have used C or C++. Goal for this topic: you can write & run a simple C program basic functions

More information

A3-R3: PROGRAMMING AND PROBLEM SOLVING THROUGH 'C' LANGUAGE

A3-R3: PROGRAMMING AND PROBLEM SOLVING THROUGH 'C' LANGUAGE A3-R3: PROGRAMMING AND PROBLEM SOLVING THROUGH 'C' LANGUAGE NOTE: 1. There are TWO PARTS in this Module/Paper. PART ONE contains FOUR questions and PART TWO contains FIVE questions. 2. PART ONE is to be

More information

Variables Data types Variable I/O. C introduction. Variables. Variables 1 / 14

Variables Data types Variable I/O. C introduction. Variables. Variables 1 / 14 C introduction Variables Variables 1 / 14 Contents Variables Data types Variable I/O Variables 2 / 14 Usage Declaration: t y p e i d e n t i f i e r ; Assignment: i d e n t i f i e r = v a l u e ; Definition

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

EECS 388 C Introduction. Gary J. Minden August 29, 2016

EECS 388 C Introduction. Gary J. Minden August 29, 2016 EECS 388 C Introduction Gary J. Minden August 29, 2016 1 C Developed at AT&T Bell Laboratories in the early 1970s by Dennis Richie Intended as a systems programming language, that is used to write operating

More information

Absolute C++ Walter Savitch

Absolute C++ Walter Savitch Absolute C++ sixth edition Walter Savitch Global edition This page intentionally left blank Absolute C++, Global Edition Cover Title Page Copyright Page Preface Acknowledgments Brief Contents Contents

More information

5.Coding for 64-Bit Programs

5.Coding for 64-Bit Programs Chapter 5 5.Coding for 64-Bit Programs This chapter provides information about ways to write/update your code so that you can take advantage of the Silicon Graphics implementation of the IRIX 64-bit operating

More information

Chapter 2 Basic Elements of C++

Chapter 2 Basic Elements of C++ C++ Programming: From Problem Analysis to Program Design, Fifth Edition 2-1 Chapter 2 Basic Elements of C++ At a Glance Instructor s Manual Table of Contents Overview Objectives s Quick Quizzes Class Discussion

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

Object-Oriented Programming

Object-Oriented Programming iuliana@cs.ubbcluj.ro Babes-Bolyai University 2018 Overview 1 2 3 4 5 6 7 I No beard, no belly, no guru... Ken Thompson (B), Dennis Ritchie (C) - UNIX Bjarne Stroustrup (C++) James Gosling (Java) Figure:

More information

Motivation was to facilitate development of systems software, especially OS development.

Motivation was to facilitate development of systems software, especially OS development. A History Lesson C Basics 1 Development of language by Dennis Ritchie at Bell Labs culminated in the C language in 1972. Motivation was to facilitate development of systems software, especially OS development.

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

Lexical Considerations

Lexical Considerations Massachusetts Institute of Technology Department of Electrical Engineering and Computer Science 6.035, Fall 2005 Handout 6 Decaf Language Wednesday, September 7 The project for the course is to write a

More information

This lists all known errors in The C Programming Language, Second Edition, by Brian Kernighan and Dennis Ritchie (Prentice-Hall, 1988).

This lists all known errors in The C Programming Language, Second Edition, by Brian Kernighan and Dennis Ritchie (Prentice-Hall, 1988). Errata for The C Programming Language, Second Edition This lists all known errors in The C Programming Language, Second Edition, by Brian Kernighan and Dennis Ritchie (Prentice-Hall, 1988). The pagination

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

Language Design COMS W4115. Prof. Stephen A. Edwards Fall 2006 Columbia University Department of Computer Science

Language Design COMS W4115. Prof. Stephen A. Edwards Fall 2006 Columbia University Department of Computer Science Language Design COMS W4115 Katsushika Hokusai, In the Hollow of a Wave off the Coast at Kanagawa, 1827 Prof. Stephen A. Edwards Fall 2006 Columbia University Department of Computer Science Language Design

More information

Procedural programming with C

Procedural programming with C Procedural programming with C Dr. C. Constantinides Department of Computer Science and Software Engineering Concordia University Montreal, Canada August 11, 2016 1 / 77 Functions Similarly to its mathematical

More information