The if-statement. Simple and compound statements. The if-statement comes in two forms: Simple statements:
|
|
- Nora Berry
- 7 years ago
- Views:
Transcription
1 1 2 Simple and compound s The if- Simple s: E.g.: expression; Various jumps : break, goto, continue, return. k = a * p + 3; printf("k = %d\n", k); 1 + 2; ; The if- comes in two forms: or E.g.: if (expression) if (expression) else Compound s: declarations s if (n > 0) n--; else printf("!\n"); n = 100; 3 4 The if- (cont). The switch- if (c == a ) else if (c == b ) else if (c == c ) else What happens below? Assume i = 0 and consider both the case decrement = 0 and decrement = 1. if (decrement) if (i > 0) i--; else i++; The switch- is similar to case in Pascal: switch (expression) case label 1 : s case label 2 : s default: s Note: expression of some integer type. Each label must be a constant. Fall through! Explicit breaks needed!
2 5 6 The switch- (cont.) The while and do s Example: Syntax: switch (c) case a : i++; break; case : case \t : case \n : blank = 1; break; default: j++; break; while (expression) do while (expression); Example: int fac(int n) int f, i; f = i = 1; while (++i <= n) f *= i; 7 8 The for- Function definition using prototypes Very common. Syntax: for (exp 1 ; exp 2 ; exp 3 ) Equivalent to: exp 1 ; while (exp 2 ) exp 3 ; Examples. for (;;) printf("hello!\n"); s = 0; for (i = 1; i <= 10; i++) s += i; for (s=0, i=1; i<=10; s+=(i++)); The general form of a function definition: type name(formal args) local vars code where formal args is a list of the form: type 1 arg 1,, type n arg n An example: double max(double x, double y) if (x > y) return x; return y;
3 9 10 Function definition (cont.) Two special prototypes: No parameters: type name(void) /*body*/ Variable number of parameters: type name(args, ) /*body*/ As an example, the printf-prototype: int printf(const char *format, ) Functions without a result ( procedures ): void foo(formal args) /*body*/ Only return s of the form return; are allowed in the body. Declaring functions using prototypes A function declaration looks like: type name(formal args); where formal args is a list of the form: type 1 arg 1,, type n arg n, or type 1,, type n What is the difference? A function declaration makes the function known to the compiler. A function may be declared more than once. A function definition gives the code for the function. A function must be defined exactly once, later in the same file or externally Generally: Definitions vs. declarations A declaration specifies what an identifier stands for. A definition is a construction that, in addition to declaring an identifier, also reserves space for it and gives its value. Old style (K&R) function definitions and declarations Old style function definition: type name(arg. names) arg. decls Typical example: As a rule, always at least declare before use. Include files (e.g. stdio.h etc.) contain declarations only. This is vital. int foo(x, y) double x; double y; Old style function declaration: type name(); E.g. int foo(); No info about number of args or their type!
4 13 14 A function call: Calling functions name(actual args.) Calling a function without arguments: name() Note: the parentheses are essential. Argument passing is always call-by-value: No reference arguments. The same effect is obtained by passing pointers by value. Examples: int foo(float, int); i = foo(1.2, 17); printf("%d\n", foo(7.77, 42); (void) printf("%d\n", 42); Storage classes Basic idea: Storage classes determine how and when storage is allocated, e.g.: Suggest that the compiler try to put a variable in a CPU register: register int i; Tell the compiler that something is defined elsewhere: external double sin(double); Unfortunately, a little complex in practice: The exact meaning of a storage class is context dependent. Somewhat complicated default assumptions. Other uses, such as controlling visibility of top level symbols For local variables. The storage class auto Default for local variables (and formal arguments). Usually not stated explicitly. Storage is automatically allocated and deallocated (on system stack) when a block is entered/left. Any initialization performed each time. A declaration of an auto object is also a definition. An auto-object must never be accessed outside of the block in which it is defined. Example: int foo(float x, int i) int n = 10, m = i; The storage class extern Separate compilation makes it necessary to tell the compiler: which symbols that are defined in another file, i.e. defined externally, which top-level symbols should be visible outside the file, i.e. visible externally. The storage class extern serves both these purposes.
5 17 18 The storage class extern (cont.) Extern function or variable declaration: Assumed by default for top-level declarations. States the type of the object. Indicates that the object is either - defined later in the same file, or - defined in another file (externally). Storage allocated for top-level variable declaration (i.e the declaration counts as a definition, implicit initialization to 0) if: - extern is not stated explicitly, - no definition is encountered later in the file. Otherwise, no storage is allocated. The storage class extern (cont.) Extern function or variable definition: Only for top-level (global) symbols. Global storage allocated, object lives throughout the entire execution. Initialization performed only once. (Actually, initialized global data comprises a section of the executable file.) Also indicates to the compiler that the symbol should be externally visible. Assumed by default for top-level definitions; usually not stated explicitly The storage class extern (cont.) The easy option: Use extern explicitly only for importing things from other modules. Be aware of that global symbols are visible outside the file, unless you say otherwise. File foo.c Example on extern usage extern int a; int foo(int i) return a * i; File main.c #include <stdio.h> extern int foo(int); int a = 10; main() printf("%d\n", foo(7)); a = 20; printf("%d\n", foo(7));
6 21 22 The storage class static For functions and variables: Like external in that a static object is initialized once and lives during the entire execution. Unlike external in that static objects are not visible externally. Also, can be applied to local variable definitions (and declarations, which then count as definitions). Example: static int fie() static int count = 0; return (++count); Constants Variables and parameters may be declared as constants: But: const int max = 7; const char end = \0 ; Not the same thing as const in Pascal. Really variables that cannot be assigned to. Use #define if you need compile-time constants (for sizes of arrays etc.). To see the difference: int foo(int a, int b) const int m = max(a,b); /* body of function */ Strings in C No real strings in C. Instead: Pointer to a sequence of char. Explicit termination by the null character, \0. printf("hello!\n"); is represented as printf( ); H e l l o! \n \0 Declaration: T a[n]; Basic arrays The variable a is an array of N elements of the type T. Subscripting: a[0], a[1],, a[n-1] No range checks! Arrays may be initialized when declared: float f[3] = 0.0, 1.0, 2.0; int a[100] = 0; char s[] = a, b, c, \0 ; char s[] = "abc"; Default initialization to 0 of static and extern arrays.
7 25 26 #include <stdio.h> #define N 20 Bubblesort main() int a[n], i, j, temp; for (i = 0; i < N; i++) scanf("%d", &a[i]); for (i = 0; i < N-1; i++) for (j = N-1; j > i; j--) if (a[j-1] > a[j]) temp = a[j-1]; a[j-1] = a[j]; a[j] = temp; for (i = 0; i < N; i++) printf("%d ", a[i]); Declaration: T *ap; Basic pointers ap can hold a pointer to an object of type T. Taking the address of a variable of type T by using & creates a pointer to an object of type T: int a, b, *ap = &a, *bp = &b; char *s = "abc"; a: b: ap: bp: s: a b c \ Basic pointers (cont.) Dereferencing pointers: a) *ap = 1; b = *ap + 1; b1) ap = bp b2) *ap = *bp; a: b: ap: a b1 b2 1 2 a: b: ap: 1 2 a: b: ap: 2 2 Call-by-value vs. call-by-reference Call-by-value (C or C++): int y = 1; void foo(int x) x++ foo(y); y is still 1 after the call (contents of y copied to x which is just a local variable). Call-by-reference (C++): int y = 1; bp: bp: bp: void foo(int &x) x++ foo(y); y is 2 after the call since the formal argument x refers to the actual argument y during the call.
8 29 30 Call-by-reference in C Arguments are always passed by value in C. No concept of reference parameters. Instead, pointers are passed explicitly. #include <stdio.h> void foo(int *ap, int *bp) scanf("%d", ap); *bp = *ap * 2; Exercise 1 Write a loop to reverse an array int a[n], i.e. swap a[0] and a[n-1], a[1] and a[n-2], etc. Write a function that may be used to swap the contents of two integer variables. Then change your code for reversing the array so that it uses your swap function. main() int a, b, c; foo(&a, &b); scanf("%d", &c); printf("a*b=%d,c=%d\n",a*b,c); Pointer arithmetic Bubblesort revisited In C, + and - also work on pointers: An integer may be added to/subtracted from a pointer. One pointer may be subtracted from another. The basic assumption is that the pointers refer to elements in some array: T *a: T *b: T x[n] a-2 a+3 Pointer arithmetic is often used to access arrays by pointer stepping. #include <stdio.h> #define N 20 main() int a[n], *ip, *jp, temp; for (ip = &a[0]; ip < &a[n]; ip++) scanf("%d", ip); for (ip = &a[0]; ip < &a[n-1]; ip++) for (jp = &a[n-1]; jp > ip; jp--) if (*(jp-1) > *jp) temp = *(jp-1); *(jp-1) = *jp; *jp = temp; for (ip = &a[0]; ip < &a[n]; ip++) printf("%d ", *ip);
9 33 34 The relationship between arrays and pointers The relationship between arrays and pointers (cont.) Arrays and pointers are not identical! char s1[] = "hello"; char *s2 = "world"; s1: h e l l o \0 In C, an equivalence between arrays and pointers in the following sense holds: An array is, with three exceptions, converted to a pointer to its first element when used. s2: w o r l d \0 The exceptions occur when the array is: an argument to sizeof, Assume a typical 32-bit computer sizeof(s1) =? sizeof(s2) =? Is the following legal C? Why? s1 = s2; s2 = s1; an argument to &, a literal string used for initialization of a char array. In all other cases we have a = &a[0]. Thus, the for-loops earlier could have been written: for (ip = a; ip < &a[n]; ip++) Given The relationship between arrays and pointers (cont.) char s1[] = "hello"; char *s2 = "world"; the equivalence explains why: s1 = s2 is as invalid as 1 = a, s2 = s1 is a legal assignment, sizeof(s1) = 6. Moreover, by definition we have: s1[i] *(s1 + i) s2[i] *(s2 + i) The equivalence (together with pointer arithmetic) explains why this works. Arrays as arguments to functions It is always a pointer to the first element that is passed! void foo(t *a) main() T a[n]; foo(a); Alternative, equivalent ways of declaring foo: void foo(t a[]) void foo(t a[n])
10 37 38 Arrays as arguments to functions (cont.) What gets printed when foo is called? void foo(int a[10]) int b[10]; printf("%d, %d\n", sizeof(a), sizeof(b)); Reading a string: char s[20]; scanf("%19s", s); s on its own is the address of the array: no & in this case! There must be room for the terminating \0. Exercise 2 Assume a typical 32-bit architecture, and: char s[5]="abcd", (*cap)[5]; Answer the following: sizeof(s) =? sizeof(cap) =? Is cap = s OK? Is cap = &s OK? sizeof(*cap) =? sizeof(&s) =? sizeof(*s) =? Is the following legal C? If so, what gets printed? printf("%c\n", 5["abcdef"]); 39 Solution exercise 1 Loop to reverse an array int a[n]: int i, temp; for (i = 0; i < N/2; i++) temp = a[i]; a[i] = a[(n-1)-i]; a[(n-1)-i] = temp; Function to swap two integer variables. void swap(int *a, int *b) int temp; temp = *a; *a = *b; *b = temp; Rewriting the loop body: swap(&a[i], &a[(n-1)-i]);
Sources: On the Web: Slides will be available on:
C programming Introduction The basics of algorithms Structure of a C code, compilation step Constant, variable type, variable scope Expression and operators: assignment, arithmetic operators, comparison,
More informationThe C Programming Language course syllabus associate level
TECHNOLOGIES The C Programming Language course syllabus associate level Course description The course fully covers the basics of programming in the C programming language and demonstrates fundamental programming
More informationASCII Encoding. The char Type. Manipulating Characters. Manipulating Characters
The char Type ASCII Encoding The C char type stores small integers. It is usually 8 bits. char variables guaranteed to be able to hold integers 0.. +127. char variables mostly used to store characters
More informationarrays C Programming Language - Arrays
arrays So far, we have been using only scalar variables scalar meaning a variable with a single value But many things require a set of related values coordinates or vectors require 3 (or 2, or 4, or more)
More informationKeywords are identifiers having predefined meanings in C programming language. The list of keywords used in standard C are : unsigned void
1. Explain C tokens Tokens are basic building blocks of a C program. A token is the smallest element of a C program that is meaningful to the compiler. The C compiler recognizes the following kinds of
More informationEmbedded Systems. Review of ANSI C Topics. A Review of ANSI C and Considerations for Embedded C Programming. Basic features of C
Embedded Systems A Review of ANSI C and Considerations for Embedded C Programming Dr. Jeff Jackson Lecture 2-1 Review of ANSI C Topics Basic features of C C fundamentals Basic data types Expressions Selection
More informationObject-Oriented Design Lecture 4 CSU 370 Fall 2007 (Pucella) Tuesday, Sep 18, 2007
Object-Oriented Design Lecture 4 CSU 370 Fall 2007 (Pucella) Tuesday, Sep 18, 2007 The Java Type System By now, you have seen a fair amount of Java. Time to study in more depth the foundations of the language,
More informationSemantic Analysis: Types and Type Checking
Semantic Analysis Semantic Analysis: Types and Type Checking CS 471 October 10, 2007 Source code Lexical Analysis tokens Syntactic Analysis AST Semantic Analysis AST Intermediate Code Gen lexical errors
More informationSenem Kumova Metin & Ilker Korkmaz 1
Senem Kumova Metin & Ilker Korkmaz 1 A loop is a block of code that can be performed repeatedly. A loop is controlled by a condition that is checked each time through the loop. C supports two categories
More informationC++ Programming Language
C++ Programming Language Lecturer: Yuri Nefedov 7th and 8th semesters Lectures: 34 hours (7th semester); 32 hours (8th semester). Seminars: 34 hours (7th semester); 32 hours (8th semester). Course abstract
More information1 Abstract Data Types Information Hiding
1 1 Abstract Data Types Information Hiding 1.1 Data Types Data types are an integral part of every programming language. ANSI-C has int, double and char to name just a few. Programmers are rarely content
More informationX86-64 Architecture Guide
X86-64 Architecture Guide For the code-generation project, we shall expose you to a simplified version of the x86-64 platform. Example Consider the following Decaf program: class Program { int foo(int
More informationPemrograman Dasar. Basic Elements Of Java
Pemrograman Dasar Basic Elements Of Java Compiling and Running a Java Application 2 Portable Java Application 3 Java Platform Platform: hardware or software environment in which a program runs. Oracle
More informationName: Class: Date: 9. The compiler ignores all comments they are there strictly for the convenience of anyone reading the program.
Name: Class: Date: Exam #1 - Prep True/False Indicate whether the statement is true or false. 1. Programming is the process of writing a computer program in a language that the computer can respond to
More informationFirst Java Programs. V. Paúl Pauca. CSC 111D Fall, 2015. Department of Computer Science Wake Forest University. Introduction to Computer Science
First Java Programs V. Paúl Pauca Department of Computer Science Wake Forest University CSC 111D Fall, 2015 Hello World revisited / 8/23/15 The f i r s t o b l i g a t o r y Java program @author Paul Pauca
More informationThe programming language C. sws1 1
The programming language C sws1 1 The programming language C invented by Dennis Ritchie in early 1970s who used it to write the first Hello World program C was used to write UNIX Standardised as K&C (Kernighan
More informationInformatica e Sistemi in Tempo Reale
Informatica e Sistemi in Tempo Reale Introduction to C programming Giuseppe Lipari http://retis.sssup.it/~lipari Scuola Superiore Sant Anna Pisa October 25, 2010 G. Lipari (Scuola Superiore Sant Anna)
More informationIntroduction to Java
Introduction to Java The HelloWorld program Primitive data types Assignment and arithmetic operations User input Conditional statements Looping Arrays CSA0011 Matthew Xuereb 2008 1 Java Overview A high
More informationC++ INTERVIEW QUESTIONS
C++ INTERVIEW QUESTIONS http://www.tutorialspoint.com/cplusplus/cpp_interview_questions.htm Copyright tutorialspoint.com Dear readers, these C++ Interview Questions have been designed specially to get
More informationThe Function Pointer
The Function Pointer 1. Introduction to Function Pointers Function Pointers provide some extremely interesting, efficient and elegant programming techniques. You can use them to replace switch/if-statements,
More informationPART-A Questions. 2. How does an enumerated statement differ from a typedef statement?
1. Distinguish & and && operators. PART-A Questions 2. How does an enumerated statement differ from a typedef statement? 3. What are the various members of a class? 4. Who can access the protected members
More informationTutorial on C Language Programming
Tutorial on C Language Programming Teodor Rus rus@cs.uiowa.edu The University of Iowa, Department of Computer Science Introduction to System Software p.1/64 Tutorial on C programming C program structure:
More informationMoving from CS 61A Scheme to CS 61B Java
Moving from CS 61A Scheme to CS 61B Java Introduction Java is an object-oriented language. This document describes some of the differences between object-oriented programming in Scheme (which we hope you
More informationBasic Java Constructs and Data Types Nuts and Bolts. Looking into Specific Differences and Enhancements in Java compared to C
Basic Java Constructs and Data Types Nuts and Bolts Looking into Specific Differences and Enhancements in Java compared to C 1 Contents Hello World Program Statements Explained Java Program Structure in
More information9 Control Statements. 9.1 Introduction. 9.2 Objectives. 9.3 Statements
9 Control Statements 9.1 Introduction The normal flow of execution in a high level language is sequential, i.e., each statement is executed in the order of its appearance in the program. However, depending
More informationJava Interview Questions and Answers
1. What is the most important feature of Java? Java is a platform independent language. 2. What do you mean by platform independence? Platform independence means that we can write and compile the java
More informationMemory management. Announcements. Safe user input. Function pointers. Uses of function pointers. Function pointer example
Announcements Memory management Assignment 2 posted, due Friday Do two of the three problems Assignment 1 graded see grades on CMS Lecture 7 CS 113 Spring 2008 2 Safe user input If you use scanf(), include
More informationLecture 11 Doubly Linked Lists & Array of Linked Lists. Doubly Linked Lists
Lecture 11 Doubly Linked Lists & Array of Linked Lists In this lecture Doubly linked lists Array of Linked Lists Creating an Array of Linked Lists Representing a Sparse Matrix Defining a Node for a Sparse
More informationParameter passing in LISP
Parameter passing in LISP The actual parameters in a function call are always expressions, represented as lists structures. LISP provides two main methods of parameter passing: Pass/Call-by-value. The
More informationParameter Passing. Parameter Passing. Parameter Passing Modes in Fortran. Parameter Passing Modes in C
Parameter Passing In this set of notes you will learn about: Parameter passing modes Call by Call by reference Call by sharing Call by result Call by /result Call by name Subroutine closures as parameters
More informationStorage Classes CS 110B - Rule Storage Classes Page 18-1 \handouts\storclas
CS 110B - Rule Storage Classes Page 18-1 Attributes are distinctive features of a variable. Data type, int or double for example, is an attribute. Storage class is another attribute. There are four storage
More informationC PROGRAMMING FOR MATHEMATICAL COMPUTING
UNIVERSITY OF CALICUT SCHOOL OF DISTANCE EDUCATION BSc MATHEMATICS (2011 Admission Onwards) VI Semester Elective Course C PROGRAMMING FOR MATHEMATICAL COMPUTING QUESTION BANK Multiple Choice Questions
More informationAbout The Tutorial. Audience. Prerequisites. Copyright & Disclaimer
About The Tutorial C is a general-purpose, procedural, imperative computer programming language developed in 1972 by Dennis M. Ritchie at the Bell Telephone Laboratories to develop the UNIX operating system.
More informationDebugging. Common Semantic Errors ESE112. Java Library. It is highly unlikely that you will write code that will work on the first go
Debugging ESE112 Java Programming: API, Psuedo-Code, Scope It is highly unlikely that you will write code that will work on the first go Bugs or errors Syntax Fixable if you learn to read compiler error
More informationObject Oriented Software Design
Object Oriented Software Design Introduction to Java - II Giuseppe Lipari http://retis.sssup.it/~lipari Scuola Superiore Sant Anna Pisa October 28, 2010 G. Lipari (Scuola Superiore Sant Anna) Introduction
More informationIntroduction to Java Applications. 2005 Pearson Education, Inc. All rights reserved.
1 2 Introduction to Java Applications 2.2 First Program in Java: Printing a Line of Text 2 Application Executes when you use the java command to launch the Java Virtual Machine (JVM) Sample program Displays
More informationPL / SQL Basics. Chapter 3
PL / SQL Basics Chapter 3 PL / SQL Basics PL / SQL block Lexical units Variable declarations PL / SQL types Expressions and operators PL / SQL control structures PL / SQL style guide 2 PL / SQL Block Basic
More information6.s096. Introduction to C and C++
6.s096 Introduction to C and C++ 1 Why? 2 1 You seek performance 3 1 You seek performance zero-overhead principle 4 2 You seek to interface directly with hardware 5 3 That s kinda it 6 C a nice way to
More informationHow To Port A Program To Dynamic C (C) (C-Based) (Program) (For A Non Portable Program) (Un Portable) (Permanent) (Non Portable) C-Based (Programs) (Powerpoint)
TN203 Porting a Program to Dynamic C Introduction Dynamic C has a number of improvements and differences compared to many other C compiler systems. This application note gives instructions and suggestions
More informationMISRA-C:2012 Standards Model Summary for C / C++
MISRA-C:2012 Standards Model Summary for C / C++ The LDRA tool suite is developed and certified to BS EN ISO 9001:2000. This information is applicable to version 9.4.2 of the LDRA tool suite. It is correct
More informationpublic static void main(string[] args) { System.out.println("hello, world"); } }
Java in 21 minutes hello world basic data types classes & objects program structure constructors garbage collection I/O exceptions Strings Hello world import java.io.*; public class hello { public static
More informationChapter 13 Storage classes
Chapter 13 Storage classes 1. Storage classes 2. Storage Class auto 3. Storage Class extern 4. Storage Class static 5. Storage Class register 6. Global and Local Variables 7. Nested Blocks with the Same
More informationScoping (Readings 7.1,7.4,7.6) Parameter passing methods (7.5) Building symbol tables (7.6)
Semantic Analysis Scoping (Readings 7.1,7.4,7.6) Static Dynamic Parameter passing methods (7.5) Building symbol tables (7.6) How to use them to find multiply-declared and undeclared variables Type checking
More informationObject Oriented Software Design
Object Oriented Software Design Introduction to Java - II Giuseppe Lipari http://retis.sssup.it/~lipari Scuola Superiore Sant Anna Pisa September 14, 2011 G. Lipari (Scuola Superiore Sant Anna) Introduction
More information5 Arrays and Pointers
5 Arrays and Pointers 5.1 One-dimensional arrays Arrays offer a convenient way to store and access blocks of data. Think of arrays as a sequential list that offers indexed access. For example, a list of
More informationCOMP 356 Programming Language Structures Notes for Chapter 10 of Concepts of Programming Languages Implementing Subprograms.
COMP 356 Programming Language Structures Notes for Chapter 10 of Concepts of Programming Languages Implementing Subprograms 1 Activation Records activation declaration location Recall that an activation
More informationGoals for This Lecture:
Goals for This Lecture: Understand the pass-by-value and passby-reference argument passing mechanisms of C++ Understand the use of C++ arrays Understand how arrays are passed to C++ functions Call-by-value
More informationJAVA - QUICK GUIDE. Java SE is freely available from the link Download Java. So you download a version based on your operating system.
http://www.tutorialspoint.com/java/java_quick_guide.htm JAVA - QUICK GUIDE Copyright tutorialspoint.com What is Java? Java is: Object Oriented Platform independent: Simple Secure Architectural- neutral
More informationObject Oriented Software Design II
Object Oriented Software Design II Introduction to C++ Giuseppe Lipari http://retis.sssup.it/~lipari Scuola Superiore Sant Anna Pisa February 20, 2012 G. Lipari (Scuola Superiore Sant Anna) C++ Intro February
More informationAn Incomplete C++ Primer. University of Wyoming MA 5310
An Incomplete C++ Primer University of Wyoming MA 5310 Professor Craig C. Douglas http://www.mgnet.org/~douglas/classes/na-sc/notes/c++primer.pdf C++ is a legacy programming language, as is other languages
More informationInstruction Set Architecture (ISA)
Instruction Set Architecture (ISA) * Instruction set architecture of a machine fills the semantic gap between the user and the machine. * ISA serves as the starting point for the design of a new machine
More informationExample of a Java program
Example of a Java program class SomeNumbers static int square (int x) return x*x; public static void main (String[] args) int n=20; if (args.length > 0) // change default n = Integer.parseInt(args[0]);
More informationChapter 5 Names, Bindings, Type Checking, and Scopes
Chapter 5 Names, Bindings, Type Checking, and Scopes Chapter 5 Topics Introduction Names Variables The Concept of Binding Type Checking Strong Typing Scope Scope and Lifetime Referencing Environments Named
More informationA deeper look at Inline functions
A deeper look at Inline functions I think it s safe to say that all Overload readers know what C++ inline functions are. When we declare a function or member function as inline we are trying to avoid the
More informationComputer Programming I
Computer Programming I COP 2210 Syllabus Spring Semester 2012 Instructor: Greg Shaw Office: ECS 313 (Engineering and Computer Science Bldg) Office Hours: Tuesday: 2:50 4:50, 7:45 8:30 Thursday: 2:50 4:50,
More informationSoftware Engineering Concepts: Testing. Pointers & Dynamic Allocation. CS 311 Data Structures and Algorithms Lecture Slides Monday, September 14, 2009
Software Engineering Concepts: Testing Simple Class Example continued Pointers & Dynamic Allocation CS 311 Data Structures and Algorithms Lecture Slides Monday, September 14, 2009 Glenn G. Chappell Department
More informationLecture 22: C Programming 4 Embedded Systems
Lecture 22: C Programming 4 Embedded Systems Today s Goals Basic C programming process Variables and constants in C Pointers to access addresses Using a High Level Language High-level languages More human
More informationComp151. Definitions & Declarations
Comp151 Definitions & Declarations Example: Definition /* reverse_printcpp */ #include #include using namespace std; int global_var = 23; // global variable definition void reverse_print(const
More information13 Classes & Objects with Constructors/Destructors
13 Classes & Objects with Constructors/Destructors 13.1 Introduction In object oriented programming, the emphasis is on data rather than function. Class is a way that binds the data & function together.
More informationKeil C51 Cross Compiler
Keil C51 Cross Compiler ANSI C Compiler Generates fast compact code for the 8051 and it s derivatives Advantages of C over Assembler Do not need to know the microcontroller instruction set Register allocation
More informationComputer Programming Tutorial
Computer Programming Tutorial COMPUTER PROGRAMMING TUTORIAL by tutorialspoint.com tutorialspoint.com i ABOUT THE TUTORIAL Computer Prgramming Tutorial Computer programming is the act of writing computer
More informationFunctions and Parameter Passing
Chapter 5: Functions and Parameter Passing In this chapter, we examine the difference between function calls in C and C++ and the resulting difference in the way functions are defined in the two languages.
More informationPROGRAMMING IN C PROGRAMMING IN C CONTENT AT A GLANCE
PROGRAMMING IN C CONTENT AT A GLANCE 1 MODULE 1 Unit 1 : Basics of Programming Unit 2 : Fundamentals Unit 3 : C Operators MODULE 2 unit 1 : Input Output Statements unit 2 : Control Structures unit 3 :
More informationStacks. Linear data structures
Stacks Linear data structures Collection of components that can be arranged as a straight line Data structure grows or shrinks as we add or remove objects ADTs provide an abstract layer for various operations
More informationWe will learn the Python programming language. Why? Because it is easy to learn and many people write programs in Python so we can share.
LING115 Lecture Note Session #4 Python (1) 1. Introduction As we have seen in previous sessions, we can use Linux shell commands to do simple text processing. We now know, for example, how to count words.
More informationIntroduction to Python
Caltech/LEAD Summer 2012 Computer Science Lecture 2: July 10, 2012 Introduction to Python The Python shell Outline Python as a calculator Arithmetic expressions Operator precedence Variables and assignment
More informationIS0020 Program Design and Software Tools Midterm, Feb 24, 2004. Instruction
IS0020 Program Design and Software Tools Midterm, Feb 24, 2004 Name: Instruction There are two parts in this test. The first part contains 50 questions worth 80 points. The second part constitutes 20 points
More informationMULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question.
Exam Name MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question. 1) The JDK command to compile a class in the file Test.java is A) java Test.java B) java
More informationObject Oriented Software Design II
Object Oriented Software Design II C++ intro Giuseppe Lipari http://retis.sssup.it/~lipari Scuola Superiore Sant Anna Pisa February 26, 2012 G. Lipari (Scuola Superiore Sant Anna) C++ Intro February 26,
More information2) Write in detail the issues in the design of code generator.
COMPUTER SCIENCE AND ENGINEERING VI SEM CSE Principles of Compiler Design Unit-IV Question and answers UNIT IV CODE GENERATION 9 Issues in the design of code generator The target machine Runtime Storage
More informationMPLAB TM C30 Managed PSV Pointers. Beta support included with MPLAB C30 V3.00
MPLAB TM C30 Managed PSV Pointers Beta support included with MPLAB C30 V3.00 Contents 1 Overview 2 1.1 Why Beta?.............................. 2 1.2 Other Sources of Reference..................... 2 2
More informationChapter 2 Introduction to Java programming
Chapter 2 Introduction to Java programming 1 Keywords boolean if interface class true char else package volatile false byte final switch while throws float private case return native void protected break
More informationChapter One Introduction to Programming
Chapter One Introduction to Programming 1-1 Algorithm and Flowchart Algorithm is a step-by-step procedure for calculation. More precisely, algorithm is an effective method expressed as a finite list of
More informationStatic vs. Dynamic. Lecture 10: Static Semantics Overview 1. Typical Semantic Errors: Java, C++ Typical Tasks of the Semantic Analyzer
Lecture 10: Static Semantics Overview 1 Lexical analysis Produces tokens Detects & eliminates illegal tokens Parsing Produces trees Detects & eliminates ill-formed parse trees Static semantic analysis
More informationIntermediate Code. Intermediate Code Generation
Intermediate Code CS 5300 - SJAllan Intermediate Code 1 Intermediate Code Generation The front end of a compiler translates a source program into an intermediate representation Details of the back end
More informationOutline. Conditional Statements. Logical Data in C. Logical Expressions. Relational Examples. Relational Operators
Conditional Statements For computer to make decisions, must be able to test CONDITIONS IF it is raining THEN I will not go outside IF Count is not zero THEN the Average is Sum divided by Count Conditions
More informationSymbol Tables. Introduction
Symbol Tables Introduction A compiler needs to collect and use information about the names appearing in the source program. This information is entered into a data structure called a symbol table. The
More informationChapter 2: Elements of Java
Chapter 2: Elements of Java Basic components of a Java program Primitive data types Arithmetic expressions Type casting. The String type (introduction) Basic I/O statements Importing packages. 1 Introduction
More informationCommon Data Structures
Data Structures 1 Common Data Structures Arrays (single and multiple dimensional) Linked Lists Stacks Queues Trees Graphs You should already be familiar with arrays, so they will not be discussed. Trees
More informationC++ Overloading, Constructors, Assignment operator
C++ Overloading, Constructors, Assignment operator 1 Overloading Before looking at the initialization of objects in C++ with constructors, we need to understand what function overloading is In C, two functions
More informationC++FA 3.1 OPTIMIZING C++
C++FA 3.1 OPTIMIZING C++ Ben Van Vliet Measuring Performance Performance can be measured and judged in different ways execution time, memory usage, error count, ease of use and trade offs usually have
More informationChapter 13 - The Preprocessor
Chapter 13 - The Preprocessor Outline 13.1 Introduction 13.2 The#include Preprocessor Directive 13.3 The#define Preprocessor Directive: Symbolic Constants 13.4 The#define Preprocessor Directive: Macros
More informationXMOS Programming Guide
XMOS Programming Guide Document Number: Publication Date: 2014/10/9 XMOS 2014, All Rights Reserved. XMOS Programming Guide 2/108 SYNOPSIS This document provides a consolidated guide on how to program XMOS
More informationSimple C Programs. Goals for this Lecture. Help you learn about:
Simple C Programs 1 Goals for this Lecture Help you learn about: Simple C programs Program structure Defining symbolic constants Detecting and reporting failure Functionality of the gcc command Preprocessor,
More informationBachelors of Computer Application Programming Principle & Algorithm (BCA-S102T)
Unit- I Introduction to c Language: C is a general-purpose computer programming language developed between 1969 and 1973 by Dennis Ritchie at the Bell Telephone Laboratories for use with the Unix operating
More informationC Interview Questions
http://techpreparation.com C Interview Questions And Answers 2008 V i s i t T e c h P r e p a r a t i o n. c o m f o r m o r e i n t e r v i e w q u e s t i o n s a n d a n s w e r s C Interview Questions
More informationPROG0101 Fundamentals of Programming PROG0101 FUNDAMENTALS OF PROGRAMMING. Chapter 3 Algorithms
PROG0101 FUNDAMENTALS OF PROGRAMMING Chapter 3 1 Introduction to A sequence of instructions. A procedure or formula for solving a problem. It was created mathematician, Mohammed ibn-musa al-khwarizmi.
More informationUIL Computer Science for Dummies by Jake Warren and works from Mr. Fleming
UIL Computer Science for Dummies by Jake Warren and works from Mr. Fleming 1 2 Foreword First of all, this book isn t really for dummies. I wrote it for myself and other kids who are on the team. Everything
More informationModule 2 Stacks and Queues: Abstract Data Types
Module 2 Stacks and Queues: Abstract Data Types A stack is one of the most important and useful non-primitive linear data structure in computer science. It is an ordered collection of items into which
More informationPassing 1D arrays to functions.
Passing 1D arrays to functions. In C++ arrays can only be reference parameters. It is not possible to pass an array by value. Therefore, the ampersand (&) is omitted. What is actually passed to the function,
More informationProgramming Language Features (cont.) CMSC 330: Organization of Programming Languages. Parameter Passing in OCaml. Call-by-Value
CMSC 33: Organization of Programming Languages Programming Language Features (cont.) Names & binding Namespaces Static (lexical) scopes Dynamic scopes Polymorphism Parametric Subtype Ad-hoc Parameter Passing
More informationGlossary of Object Oriented Terms
Appendix E Glossary of Object Oriented Terms abstract class: A class primarily intended to define an instance, but can not be instantiated without additional methods. abstract data type: An abstraction
More informationHandout 1. Introduction to Java programming language. Java primitive types and operations. Reading keyboard Input using class Scanner.
Handout 1 CS603 Object-Oriented Programming Fall 15 Page 1 of 11 Handout 1 Introduction to Java programming language. Java primitive types and operations. Reading keyboard Input using class Scanner. Java
More informationUnix Shell Scripts. Contents. 1 Introduction. Norman Matloff. July 30, 2008. 1 Introduction 1. 2 Invoking Shell Scripts 2
Unix Shell Scripts Norman Matloff July 30, 2008 Contents 1 Introduction 1 2 Invoking Shell Scripts 2 2.1 Direct Interpretation....................................... 2 2.2 Indirect Interpretation......................................
More informationIntroduction to Data Structures
Introduction to Data Structures Albert Gural October 28, 2011 1 Introduction When trying to convert from an algorithm to the actual code, one important aspect to consider is how to store and manipulate
More informationStatements and Control Flow
Contents 1. Introduction 2. Types and Variables 3. Statements and Control Flow 4. Reading Input 5. Classes and Objects 6. Arrays 7. Methods 8. Scope and Lifetime 9. Utility classes 10. Introduction to
More informationNumber Conversions Dr. Sarita Agarwal (Acharya Narendra Dev College,University of Delhi)
Conversions Dr. Sarita Agarwal (Acharya Narendra Dev College,University of Delhi) INTRODUCTION System- A number system defines a set of values to represent quantity. We talk about the number of people
More informationStack Allocation. Run-Time Data Structures. Static Structures
Run-Time Data Structures Stack Allocation Static Structures For static structures, a fixed address is used throughout execution. This is the oldest and simplest memory organization. In current compilers,
More informationCS 141: Introduction to (Java) Programming: Exam 1 Jenny Orr Willamette University Fall 2013
Oct 4, 2013, p 1 Name: CS 141: Introduction to (Java) Programming: Exam 1 Jenny Orr Willamette University Fall 2013 1. (max 18) 4. (max 16) 2. (max 12) 5. (max 12) 3. (max 24) 6. (max 18) Total: (max 100)
More informationModule 816. File Management in C. M. Campbell 1993 Deakin University
M. Campbell 1993 Deakin University Aim Learning objectives Content After working through this module you should be able to create C programs that create an use both text and binary files. After working
More information