High Performance Computing in C and C++
|
|
- Kenneth Bryant
- 5 years ago
- Views:
Transcription
1 High Performance Computing in C and C++ Rita Borgo Computer Science Department, Swansea University
2 Summary Introduction to C Writing a simple C program Compiling a simple C program Running a simple C program C Compiler C Preprocessor Data Types and Type Conversions Memory Allocations Pointers File I/O
3 Today Arithmetic Operators Arrays Struct Union Bitfields Control Flows
4 Operators Mathematical operators in C are identical to those in Java. Arithmetic Operators: +, -, *, /, % (modulus) Note: % only works with integers. / division is type dependent: float x=3/2; / produces x=1 (int /) / float x=3.0/2 / produces x=1.5 (float /) / int x=3.0/2; / produces x=1 (int conversion) /
5 Operators Mathematical operators in C are identical to those in Java. Arithmetic Operators: +, -, *, /, % (modulus) Relational Operators: <=, >=, ==,!=, <, > Note: The!= represents not equal to. The == equality operator is different from the =, assignment operator. The == operator on float variables is tricky because of finite precision.
6 Operators Mathematical operators in C are identical to those in Java. Arithmetic Operators: +, -, *, /, % (modulus) Relational Operators: <=, >=, ==,!=, <, > Logical operators &&,,! Note: Short circuit: The evaluation of an expression is discontinued if the value of a conditional expression can be determined early. Be careful of any side effects in the code. Examples: (3==3) ((c=getchar())== y ). The second expression is not evaluated. (0) && ((x=x+1)>0). The second expression is not evaluated.
7 Short-Circuiting When behaviour is unpredictable: char *p = /* initialize, may or may not be NULL */ if (p (p = (char *) malloc(buf_size)) ) { /* do stuff with p */ free(p); p = NULL; } else { /* handle malloc() error */ return; }
8 Operators Mathematical operators in C are identical to those in Java. Arithmetic Operators: +, -, *, /, % (modulus) Relational Operators: <=, >=, ==,!=, <, > Logical Operators: &&,,! Bitwise Operators: &,, ^, <<, >>, ~ Note: AND, OR, XOR, left shift, right shift, one s complement AND is true only if both operands are true. OR is true if any operand is true. XOR is true if only one of the operand is true. One s Complement ~ flips every bit. Do not confuse LOGICAL (&&, ) with BITWISE operators (&, ).
9 Bitwise Operators Shifting: Example x << 2; // shifts the bits in x by 2 places to the left. Advantages: it is equivalent to a multiplication by 2. Note: shifting is much faster than actual multiplication (*) or division (/) by 2. So if you want fast multiplications or division by 2 use shifts.
10 Operators Mathematical operators in C are identical to those in Java. Arithmetic Operators: +, -, *, /, % (modulus) Relational Operators: <=, >=, ==,!=, <, > Logical Operators: &&,,! Bitwise Operators: &,, ^, <<, >>, ~ ++i, i++, --i, i-- (pre/post-increment/decrement)
11 Increment and Decrement Increment and decrement are common arithmetic operation. C provides two short cuts for the same operation: Postfix: x++ is a short cut for x=x+1 x-- is a short cut for x=x-1 y=x++ is a short cut for y=x; x=x+1. x is evaluated before it is incremented. y=x-- is a short cut for y=x; x=x-1. x is evaluated before it is decremented. Prefix: ++x is a short cut for x=x+1 x-- is a short cut for x=x-1 y=++x is a short cut for x=x+1; y=x. x is evaluated after it is incremented. y=--x is a short cut for x=x-1; y=x. x is evaluated after it is decremented.
12 Assignment Operators Another common expression type found while programming in C is of the type: var = var (op) expr x = x + 1; C provides compact assignment operators that can be used instead: x+=1 /*is the same as x=x+1 */ x-=1 /* is the same as x=x 1 */ x*=10 /*is the same as x=x 10 */ x/=2 /* is the same as x=x/2 */ x%=2 /* is the same as x=x%2 */ Note: x *= y + 2 means x = x*(y + 2) and NOT x = x*y + 2.
13 Order of Operators Order of operations: Use parentheses to override order of evaluation. Operator +,-(sign) Evaluation direction (or Associativity) right-to-left *,/,% left-to-right +,- -left-to-right =,+=,-=,*=,/=,%= right-to-left
14 Structured data objects Structured data objects are available as object array [] property enumerated, numbered from 0 struct union names and types of fields occupy same space (one of)
15 Arrays An array is a group of memory locations with the same name and type Arrays are defined by specifying an element type and number of elements int vec[100]; char str[30]; float m[10][10]; For array containing N elements, indexes are 0..N-1 Often similar to pointers
16 Arrays C does not remember how large arrays are (i.e., no length attribute) int x[10]; x[10] = 5; may work (for a while) In the block where array A is defined: sizeof A gives the number of bytes in array can compute length via sizeof A /sizeof A[0] When an array is passed as a parameter to a function the size information is not available inside the function array size is typically passed as an additional parameter PrintArray(A, VECSIZE); or as part of a struct (best, object-like) or globally #define VECSIZE 10
17 Arrays Array elements are accessed using the same syntax as in Java: array[index] Example (iteration over array): int i, sum = 0;... for (i = 0; i < VECSIZE; i++) sum += vec[i]; C does not check whether array index values are sensible (i.e., no bounds checking) vec[-1] or vec[10000] will not generate a compiler warning! if you re lucky, the program crashes with Segmentation fault (core dumped)
18 Arrays C references arrays by the address of their first element array is equivalent to &array[0] can iterate through arrays using pointers as well as indexes: int *v, *last; int sum = 0; last = &vec[vecsize-1]; for (v = vec; v <= last; v++) sum += *v;
19 2-D arrays 2-dimensional array int weekends[52][2]; [0][0] [0][1] [1][0] [1][1] [2][0] [2][1] [3][0].... weekends weekends[2][1] is same as *(weekends+2*2+1) NOT *weekends+2*2+1 :this is an int!
20 Arrays - example #include <stdio.h> void main(void) { int number[12]; /* 12 cells, one cell per student */ int index, sum = 0; /* Always initialize array before use */ for (index = 0; index < 12; index++) { number[index] = index; } /* now, number[index]=index; will cause error:why?*/ } for (index = 0; index < 12; index = index + 1) { sum += number[index]; /* sum array elements */ } return;
21 structs Similar to fields in Java object/class definitions components can be any type (but not recursive) accessed using the same syntax struct.field Example: struct {int x; char y; float z;} rec;... r.x = 3; r.y = a ; r.z= ;
22 structs Record types can be defined using a tag associated with the struct definition wrapping the struct definition inside a typedef Examples: struct complex {double real; double imag;}; struct point {double x; double y;} corner; typedef struct {double real; double imag;} Complex; struct complex a, b; Complex c,d; a and b have the same size, structure and type a and c have the same size and structure, but different types
23 structs Overall size is sum of elements, plus padding for alignment (i.e., how many bytes are allocated) but, it depends on the size and order of content (e.g., ints need to be aligned on word boundaries, since size of char is 1 and size of int is 4): struct { char x; int y; char z; } s1; sizeof(s1) =? struct { char x, z; int y; } s2; sizeof(s2) =?
24 structs - example struct person { char name[41]; int age; float height; struct { /* embedded structure */ int month; int day; int year; } birth; }; struct person me; me.birth.year=1977; struct person class[60]; /* array of info about everyone in class */ class[0].name= Gun ; class[0].birth.year=1971;
25 structs Often used to model real memory layout, e.g., typedef struct { unsigned int version:2; unsigned int p:1; unsigned int cc:4; unsigned int m:1; unsigned int pt:7; u_int16 seq; u_int32 ts; } rtp_hdr_t;
26 Dereferencing pointers to struct elements pointers to structs are common especially useful with functions (as arguments to functions or as function type) two notations for accessing elements (*sp).element = 42; y = (*sp).element; Note: *sp.element doesn t work Abbreviated alternative: sp->element = 42; y = sp->element;
27 Unions Like structs: union u_tag { } u; int ival; float fval; char *sval; but occupy same memory space can hold different types at different times overall size is largest of elements
28 Bit fields Allows aligning struct with real memory data, e.g., in protocols or device drivers Order can differ between little/big-endian systems Alignment restrictions on modern processors natural alignment Sometimes clearer than (x & 0x8000) >> 31
29 Bitfields Definition: A bit-field is a set of adjacent bits within a single word. Example: struct flag { }; unsigned int is_color :1; unsigned int has_sound :1 ; unsigned int is_ntsc :1; the number after the colons specifies the width in bits. each variables should be declared as unsigned int.
30 Bitfields and Masks Bit fields vs. masks Example: struct flag { }; unsigned int is _color :1; unsigned int has_sound :1 ; unsigned int is _ntsc :1; CLR=0x1,SND=0x2,NTSC=0x4; struct flag f; x = CLR; x =SND; x =NTSC x&= ~CLR; x&=~snd; if (x & CLR x& NTSC) f.has_sound=1;f.is_color=1 f.has_sound=0;f.is_color=0; if(f.is_color f.has_sound)
31 Control structures Same as Java sequencing: ; grouping: {...} selection: if, switch iteration: for, while
32 Sequencing and grouping statement1 ; statement2; statement n; executes each of the statements in turn a semicolon after every statement not required after a {...} block { statements} {declarations statements} treat the sequence of statements as a single operation (block) data objects may be defined at beginning of block
33 The if statement Same as Java if (condition 1 ) {statements 1 } else if (condition 2 ) {statements 2 } else if (condition n-1 ) {statements n-1 } else {statements n } evaluates statements until find one with nonzero result executes corresponding statements
34 The if statement Can omit {}, but careful if (x > 0) printf( x > 0! ); if (y > 0) printf( x and y > 0! );
35 The switch statement Allows choice based on a single value switch(expression) { } case const1: statements1; break; case const2: statements2; break; default: statementsn; Effect: evaluates integer expression looks for case with matching value executes corresponding statements (or defaults)
36 The switch statement Weather w; switch(w) { case rain: printf( bring umbrella ); case snow: printf( wear jacket ); break; case sun: printf( wear sunscreen ); break; default: printf( strange weather ); }
37 Repetition C has several control structures for repetition Statement while(c) {} do {...} while(c) for (start; cond; upd) repeats an action... zero or more times, while condition is 0 one or more times, while condition is 0 zero or more times, with initialization and update
38 The break statement break allows early exit from one loop level for (init; condition; next) { } statements1; if (condition2) break; statements2;
39 The continue statement continue skips to next iteration, ignoring rest of loop body does execute next statement for (init; condition1; next) { } statement2; if (condition2) continue; statement2; often better written as if with block
advanced data types (2) typedef. today advanced data types (3) enum. mon 23 sep 2002 defining your own types using typedef
today advanced data types (1) typedef. mon 23 sep 2002 homework #1 due today homework #2 out today quiz #1 next class 30-45 minutes long one page of notes topics: C advanced data types dynamic memory allocation
More information!! " # & / / 3 * (4 $ 5 & # #! ' $ % -!! )! 1 1 ' $ & % $ 3! : ;, ; + 3 < % 3 ( (! % #, < 1 < $ 3! # 3 < ' "
#"$)(+-,#.)/-01.2 +4365879:1; ? 2 @A B C DFEG H IJ K# L M#N " # $ " $ ( ) (+, -. / / $ (0. # 1 2 ( # " 3 4 DFEG H IJPOQ I R TS U VEW G # / / 3 (4 $ 5 # # $ - ) 1 1 6 7 8 9 $ 3 : ;, ; + 3 < 3 (
More informationCS3157: Advanced Programming. Announcement
CS3157: Advanced Programming Lecture #10 Mar 20 Shlomo Hershkop shlomo@cs.columbia.edu Announcement Welcome back from spring break Hope you ve caught up with your courses Have the exams back, will return
More informationReview 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 informationOperators in C. Staff Incharge: S.Sasirekha
Operators in C Staff Incharge: S.Sasirekha Operators An operator is a symbol which helps the user to command the computer to do a certain mathematical or logical manipulations. Operators are used in C
More informationIMPORTANT 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 informationC 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 informationReview 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 informationProgramming. Elementary Concepts
Programming Elementary Concepts Summary } C Language Basic Concepts } Comments, Preprocessor, Main } Key Definitions } Datatypes } Variables } Constants } Operators } Conditional expressions } Type conversions
More informationIntroduction. 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 informationCprE 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 informationA flow chart is a graphical or symbolic representation of a process.
Q1. Define Algorithm with example? Answer:- A sequential solution of any program that written in human language, called algorithm. Algorithm is first step of the solution process, after the analysis of
More informationUnit 3. Operators. School of Science and Technology INTRODUCTION
INTRODUCTION Operators Unit 3 In the previous units (unit 1 and 2) you have learned about the basics of computer programming, different data types, constants, keywords and basic structure of a C program.
More informationDEPARTMENT 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 informationFundamental 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 informationA 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 informationLESSON 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 informationUNIT- 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 informationRoom 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 informationChapter 7. Additional Control Structures
Chapter 7 Additional Control Structures 1 Chapter 7 Topics Switch Statement for Multi-Way Branching Do-While Statement for Looping For Statement for Looping Using break and continue Statements 2 Chapter
More informationEL2310 Scientific Programming
Lecture 11: Structures and Memory (yaseminb@kth.se) Overview Overview Lecture 11: Structures and Memory Structures Continued Memory Allocation Lecture 11: Structures and Memory Structures Continued Memory
More informationSECTION II: LANGUAGE BASICS
Chapter 5 SECTION II: LANGUAGE BASICS Operators Chapter 04: Basic Fundamentals demonstrated declaring and initializing variables. This chapter depicts how to do something with them, using operators. Operators
More informationBasic 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 informationC 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 informationAbout 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 informationStructures, Unions Alignment, Padding, Bit Fields Access, Initialization Compound Literals Opaque Structures Summary. Structures
Structures Proseminar C Grundlagen und Konzepte Michael Kuhn Research Group Scientific Computing Department of Informatics Faculty of Mathematics, Informatics und Natural Sciences University of Hamburg
More informationFundamental 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 informationFinal CSE 131B Spring 2004
Login name Signature Name Student ID Final CSE 131B Spring 2004 Page 1 Page 2 Page 3 Page 4 Page 5 Page 6 Page 7 Page 8 (25 points) (24 points) (32 points) (24 points) (28 points) (26 points) (22 points)
More informationStructures, Operators
Structures Typedef Operators Type conversion Structures, Operators Basics of Programming 1 G. Horváth, A.B. Nagy, Z. Zsóka, P. Fiala, A. Vitéz 10 October, 2018 c based on slides by Zsóka, Fiala, Vitéz
More information2/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 informationA 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 informationBasic operators, Arithmetic, Relational, Bitwise, Logical, Assignment, Conditional operators. JAVA Standard Edition
Basic operators, Arithmetic, Relational, Bitwise, Logical, Assignment, Conditional operators JAVA Standard Edition Java - Basic Operators Java provides a rich set of operators to manipulate variables.
More informationCharacter 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 informationLecture 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 informationC 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 informationInformatics 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 informationRecap. ANSI C Reserved Words C++ Multimedia Programming Lecture 2. Erwin M. Bakker Joachim Rijsdam
Multimedia Programming 2004 Lecture 2 Erwin M. Bakker Joachim Rijsdam Recap Learning C++ by example No groups: everybody should experience developing and programming in C++! Assignments will determine
More informationData 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 informationChapter 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 informationCourse 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 informationWill introduce various operators supported by C language Identify supported operations Present some of terms characterizing operators
Operators Overview Will introduce various operators supported by C language Identify supported operations Present some of terms characterizing operators Operands and Operators Mathematical or logical relationships
More informationComputer 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 informationC: 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 informationELEC 377 C Programming Tutorial. ELEC Operating Systems
ELE 377 Programming Tutorial Outline! Short Introduction! History & Memory Model of! ommon Errors I have seen over the years! Work through a linked list example on the board! - uses everything I talk about
More informationby Pearson Education, Inc. All Rights Reserved.
Let s improve the bubble sort program of Fig. 6.15 to use two functions bubblesort and swap. Function bubblesort sorts the array. It calls function swap (line 51) to exchange the array elements array[j]
More informationFundamentals 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 informationMain 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 informationWriting 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 informationProgramming. Structures, enums and unions
Programming Structures, enums and unions Summary } Structures } Declaration } Member access } Function arguments } Memory layout } Array of structures } Typedef } Enums } Unions 2 Idea! } I want to describe
More informationFeatures 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 informationC-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 informationThe Arithmetic Operators. Unary Operators. Relational Operators. Examples of use of ++ and
The Arithmetic Operators The arithmetic operators refer to the standard mathematical operators: addition, subtraction, multiplication, division and modulus. Op. Use Description + x + y adds x and y x y
More informationThe Arithmetic Operators
The Arithmetic Operators The arithmetic operators refer to the standard mathematical operators: addition, subtraction, multiplication, division and modulus. Examples: Op. Use Description + x + y adds x
More informationThese 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 informationOperators and Expressions:
Operators and Expressions: Operators and expression using numeric and relational operators, mixed operands, type conversion, logical operators, bit operations, assignment operator, operator precedence
More informationCSCI-243 Exam 1 Review February 22, 2015 Presented by the RIT Computer Science Community
CSCI-243 Exam 1 Review February 22, 2015 Presented by the RIT Computer Science Community http://csc.cs.rit.edu History and Evolution of Programming Languages 1. Explain the relationship between machine
More informationC Language Advanced Concepts. Microcomputer Architecture and Interfacing Colorado School of Mines Professor William Hoff
C Language Advanced Concepts 1 Switch Statement Syntax Example switch (expression) { } case const_expr1: statement1; case const_expr2: : statement2; default: statementn; The break statement causes control
More informationANSI 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 informationCSCI 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 informationC 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 informationHomework #3 CS2255 Fall 2012
Homework #3 CS2255 Fall 2012 MULTIPLE CHOICE 1. The, also known as the address operator, returns the memory address of a variable. a. asterisk ( * ) b. ampersand ( & ) c. percent sign (%) d. exclamation
More informationCOMP 2355 Introduction to Systems Programming
COMP 2355 Introduction to Systems Programming Christian Grothoff christian@grothoff.org http://grothoff.org/christian/ 1 Functions Similar to (static) methods in Java without the class: int f(int a, int
More informationOperators. Java operators are classified into three categories:
Operators Operators are symbols that perform arithmetic and logical operations on operands and provide a meaningful result. Operands are data values (variables or constants) which are involved in operations.
More informationUNIT - 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 informationRoadmap. Java: Assembly language: OS: Machine code: Computer system:
Roadmap C: car *c = malloc(sizeof(car)); c->miles = 100; c->gals = 17; float mpg = get_mpg(c); free(c); Assembly language: Machine code: Computer system: get_mpg: pushq movq... popq ret %rbp %rsp, %rbp
More informationXC 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 informationAgenda. Peer Instruction Question 1. Peer Instruction Answer 1. Peer Instruction Question 2 6/22/2011
CS 61C: Great Ideas in Computer Architecture (Machine Structures) Introduction to C (Part II) Instructors: Randy H. Katz David A. Patterson http://inst.eecs.berkeley.edu/~cs61c/sp11 Spring 2011 -- Lecture
More informationChapter 3: Operators, Expressions and Type Conversion
101 Chapter 3 Operators, Expressions and Type Conversion Chapter 3: Operators, Expressions and Type Conversion Objectives To use basic arithmetic operators. To use increment and decrement operators. To
More informationUNIT 3 OPERATORS. [Marks- 12]
1 UNIT 3 OPERATORS [Marks- 12] SYLLABUS 2 INTRODUCTION C supports a rich set of operators such as +, -, *,,
More informationM4.1-R3: PROGRAMMING AND PROBLEM SOLVING THROUGH C LANGUAGE
M4.1-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 informationCS 376b Computer Vision
CS 376b Computer Vision 09 / 25 / 2014 Instructor: Michael Eckmann Today s Topics Questions? / Comments? Enhancing images / masks Cross correlation Convolution C++ Cross-correlation Cross-correlation involves
More informationME 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 informationAdministrivia. Introduction to Computer Systems. Pointers, cont. Pointer example, again POINTERS. Project 2 posted, due October 6
CMSC 313 Introduction to Computer Systems Lecture 8 Pointers, cont. Alan Sussman als@cs.umd.edu Administrivia Project 2 posted, due October 6 public tests s posted Quiz on Wed. in discussion up to pointers
More informationSyntax and Variables
Syntax and Variables What the Compiler needs to understand your program, and managing data 1 Pre-Processing Any line that starts with # is a pre-processor directive Pre-processor consumes that entire line
More informationVariables 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 informationLecture 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 informationCS 61c: Great Ideas in Computer Architecture
Arrays, Strings, and Some More Pointers June 24, 2014 Review of Last Lecture C Basics Variables, functioss, control flow, types, structs Only 0 and NULL evaluate to false Pointers hold addresses Address
More information>B<82. 2Soft ware. C Language manual. Copyright COSMIC Software 1999, 2001 All rights reserved.
>B
More informationIteration. Side effects
Computer programming Iteration. Side effects Marius Minea marius@cs.upt.ro 17 October 2017 Assignment operators We ve used the simple assignment: lvalue = expression lvalue = what can be on the left of
More informationCSE 351: The Hardware/Software Interface. Section 2 Integer representations, two s complement, and bitwise operators
CSE 351: The Hardware/Software Interface Section 2 Integer representations, two s complement, and bitwise operators Integer representations In addition to decimal notation, it s important to be able to
More informationBinghamton 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 informationWriting Program in C Expressions and Control Structures (Selection Statements and Loops)
Writing Program in C Expressions and Control Structures (Selection Statements and Loops) Jan Faigl Department of Computer Science Faculty of Electrical Engineering Czech Technical University in Prague
More informationPart I Part 1 Expressions
Writing Program in C Expressions and Control Structures (Selection Statements and Loops) Jan Faigl Department of Computer Science Faculty of Electrical Engineering Czech Technical University in Prague
More informationAssoc. Prof. Dr. Marenglen Biba. (C) 2010 Pearson Education, Inc. All rights reserved.
Assoc. Prof. Dr. Marenglen Biba (C) 2010 Pearson Education, Inc. All for repetition statement do while repetition statement switch multiple-selection statement break statement continue statement Logical
More informationPHPoC vs PHP > Overview. Overview
PHPoC vs PHP > Overview Overview PHPoC is a programming language that Sollae Systems has developed. All of our PHPoC products have PHPoC interpreter in firmware. PHPoC is based on a wide use script language
More information3. Types of Algorithmic and Program Instructions
3. Types of Algorithmic and Program Instructions Objectives 1. Introduce programming language concepts of variables, constants and their data types 2. Introduce types of algorithmic and program instructions
More informationC Programming a Q & A Approach
C Programming a Q & A Approach by H.H. Tan, T.B. D Orazio, S.H. Or & Marian M.Y. Choy Chapter 2 Variables, Arithmetic Expressions and Input/Output 2.1 Variables: Naming, Declaring, Assigning and Printing
More informationCGS 3066: Spring 2015 JavaScript Reference
CGS 3066: Spring 2015 JavaScript Reference Can also be used as a study guide. Only covers topics discussed in class. 1 Introduction JavaScript is a scripting language produced by Netscape for use within
More informationBLM2031 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 informationData Structures Unit 02
Data Structures Unit 02 Bucharest University of Economic Studies Memory classes, Bit structures and operators, User data types Memory classes Define specific types of variables in order to differentiate
More informationA Quick Introduction to C Programming
A Quick Introduction to C Programming 1 C Syntax and Hello World What do the < > mean? #include inserts another file..h files are called header files. They contain stuff needed to interface to libraries
More informationCS 61C: Great Ideas in Computer Architecture Introduction to C
CS 61C: Great Ideas in Computer Architecture Introduction to C Instructors: Vladimir Stojanovic & Nicholas Weaver http://inst.eecs.berkeley.edu/~cs61c/ 1 Agenda C vs. Java vs. Python Quick Start Introduction
More information.Net Technologies. Components of.net Framework
.Net Technologies Components of.net Framework There are many articles are available in the web on this topic; I just want to add one more article over the web by explaining Components of.net Framework.
More informationC Syntax Out: 15 September, 1995
Burt Rosenberg Math 220/317: Programming II/Data Structures 1 C Syntax Out: 15 September, 1995 Constants. Integer such as 1, 0, 14, 0x0A. Characters such as A, B, \0. Strings such as "Hello World!\n",
More informationData Types and Variables in C language
Data Types and Variables in C language Disclaimer The slides are prepared from various sources. The purpose of the slides is for academic use only Operators in C C supports a rich set of operators. Operators
More informationProgramming refresher and intro to C programming
Applied mechatronics Programming refresher and intro to C programming Sven Gestegård Robertz sven.robertz@cs.lth.se Department of Computer Science, Lund University 2018 Outline 1 C programming intro 2
More informationME964 High Performance Computing for Engineering Applications
ME964 High Performance Computing for Engineering Applications Quick Overview of C Programming January 20, 2011 Dan Negrut, 2011 ME964 UW-Madison There is no reason for any individual to have a computer
More informationMechatronics 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 informationObjectives. Introduce the core C# language features class Main types variables basic input and output operators arrays control constructs comments
Basics Objectives Introduce the core C# language features class Main types variables basic input and output operators arrays control constructs comments 2 Class Keyword class used to define new type specify
More informationC 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