Slide Set 2. for ENCM 335 in Fall Steve Norman, PhD, PEng

Size: px
Start display at page:

Download "Slide Set 2. for ENCM 335 in Fall Steve Norman, PhD, PEng"

Transcription

1 Slide Set 2 for ENCM 335 in Fall 2018 Steve Norman, PhD, PEng Electrical & Computer Engineering Schulich School of Engineering University of Calgary September 2018

2 ENCM 335 Fall 2018 Slide Set 2 slide 2/56 Contents An example about types, expressions, and assignment in C Expressions and operators The int and char types are both integer types Introduction to Pointers First example program with pointers Function arguments and function parameters Pointers as function parameters

3 ENCM 335 Fall 2018 Slide Set 2 slide 3/56 Outline of Slide Set 2 An example about types, expressions, and assignment in C Expressions and operators The int and char types are both integer types Introduction to Pointers First example program with pointers Function arguments and function parameters Pointers as function parameters

4 ENCM 335 Fall 2018 Slide Set 2 slide 4/56 An example about types, expressions, and assignment in C The next few slides will step through some of the details of what this C code fragment would do on a typical computer of // Use of = in variable declarations is called // initialization. int i = 5; double x = -1.25, y = 0.0; // Use of = in a statement is called assignment. y = i + x; It s too bad that = is used for both initialization and assignment. Let s make a note about the difference between initialization and assignment.

5 ENCM 335 Fall 2018 Slide Set 2 slide 5/56 Types in the example In most modern implementations of C, the int type uses 32-bit two s-complement representation. See ENEL 353 for details of two s-complement systems! In most modern implementations of C, the double type uses a 64-bit representation that follows IEEE Standard 754. Do not worry about the details of that it s an ENCM 369 topic! It s unfortunate but necessary to use language like in most modern implementations... C standards allow some flexibility about how numbers are represented with patterns of zeros and ones.

6 ENCM 335 Fall 2018 Slide Set 2 slide 6/56 Effects of initialization The int variable i gets initialized to nodes in a circuit get voltages updated to represent this bit pattern which should make sense if you are up-to-date in ENEL 353. double variables x and y, initialized to 1.25 and 0.0, result in these bit patterns (You will not be tested on the details of number representations in ENCM 335.)

7 ENCM 335 Fall 2018 Slide Set 2 slide 7/56 What computer processors do Very roughly, all actions taken by computer processors fall into one of three categories: Copy a bit pattern from one place to another. Compute a new bit pattern, using one or two existing bit patterns as inputs. Decide what to do next this is needed for things like if statements, loops, and function call and return. The statement y = i + x; requires two compute steps, and at least one important copy step. (The exact number of copy steps depends on a lot of factors we don t need to know about in ENCM 335!)

8 ENCM 335 Fall 2018 Slide Set 2 slide 8/56 First compute step The expression i + x has operands of different types. The rule in C, similar to rules in most other programming languages, requires conversion of the int operand i to type double. A circuit takes the int representation of 5, which is and generates the double representation of 5.0, which is

9 ENCM 335 Fall 2018 Slide Set 2 slide 9/56 Second compute step The bit patterns for 5.0 and 1.25, which are and are fed as inputs into a circuit called a floating-point adder, which generates the double representation of 3.75 as output:

10 ENCM 335 Fall 2018 Slide Set 2 slide 10/56 Essential copy step The output of the floating-point adder, which is gets copied into the storage location for y, replacing the all-zero bit pattern that represented 0.0 with the bit pattern that represents This completes the assignment to the variable y.

11 ENCM 335 Fall 2018 Slide Set 2 slide 11/56 Outline of Slide Set 2 An example about types, expressions, and assignment in C Expressions and operators The int and char types are both integer types Introduction to Pointers First example program with pointers Function arguments and function parameters Pointers as function parameters

12 ENCM 335 Fall 2018 Slide Set 2 slide 12/56 Expressions At this point it would be useful to provide a rough definition for the term expression. An expression is an identifier (the name of a variable, parameter or function), or a constant, or a meaningful chunk of C built using identifiers, constants, and/or operators. Consider the statement Let s list y = -x + 7 * f(z); expressions within the statement that are identifiers; expressions that are constants; all the more complex expressions.

13 ENCM 335 Fall 2018 Slide Set 2 slide 13/56 Types and values for expressions Every expression has a specific type. The type of a C expression is determined when a program is compiled, not when a program is run. (In dynamically typed languages such as Python, types of expressions often are determined at run-time.) C expressions that are not constants usually have values that are computed as a program runs.

14 ENCM 335 Fall 2018 Slide Set 2 slide 14/56 Examples of operator precedence and associativity Rules about operator precedence and associativity play important roles in determining how values of expressions are computed. In the following C fragment, what values do foo and bar get? What roles do precedence and associativity play? int i = 13, j = 5, k = 2, foo, bar; foo = i + j * k; bar = i - j - k;

15 ENCM 335 Fall 2018 Slide Set 2 slide 15/56 A near-complete list of C operators The next few slides list most of the C operators, in order of highest to lowest precedence. Many C operators have the same meanings that they have in Processing. Some may be unfamiliar to you they re unique to C and C++. We ll learn most of these operators as the course progresses, so please don t try to learn all of them right away!

16 ENCM 335 Fall 2018 Slide Set 2 slide 16/56 Here is a table of the highest three levels: precedence operators associativity 1 ( ) [ ]. -> left-to-right postfix ++ postfix -- 2 prefix ++ prefix -- right-to-left! ~ sizeof unary versions of + - * & 3 cast operator: ( type name ) right-to-left Let s make a few notes.

17 ENCM 335 Fall 2018 Slide Set 2 slide 17/56 The next ten levels are filled with binary operators. A binary operator sits in between its two operands. prec. operators associativity 4 multiplicative operators: * / % left-to-right 5 additive operators: + - left-to-right 6 shift operators: << >> left-to-right 7 relational operators: < <= > >= left-to-right 8 equality operators: ==!= left-to-right 9 bitwise AND: & left-to-right 10 bitwise XOR: ^ left-to-right 11 bitwise OR: left-to-right 12 logical AND: && left-to-right 13 logical OR: left-to-right

18 ENCM 335 Fall 2018 Slide Set 2 slide 18/56 Here are the lowest three levels: precedence operators associativity 14 conditional operator:? : right-to-left 15 = += -= *= /= %= right-to-left &= ^= = <<= >>= 16 comma operator:, left-to-right Let s make a few notes and consider some examples.

19 ENCM 335 Fall 2018 Slide Set 2 slide 19/56 Example use of the logical AND operator Let s look at the program on the next page and determine the output, making careful notes about how the expression y >= 0 && y <= 10 - x is evaluated.

20 ENCM 335 Fall 2018 Slide Set 2 slide 20/56 #include <stdio.h> void foo(int x, int y); int main(void) { foo(7, -2); foo(8, 3); foo(2, 4); return 0; } void foo(int x, int y) { if (y >= 0 && y <= 10 - x) printf("yep\n"); else printf("nope\n"); }

21 ENCM 335 Fall 2018 Slide Set 2 slide 21/56 Outline of Slide Set 2 An example about types, expressions, and assignment in C Expressions and operators The int and char types are both integer types Introduction to Pointers First example program with pointers Function arguments and function parameters Pointers as function parameters

22 ENCM 335 Fall 2018 Slide Set 2 slide 22/56 The int and char types are both integer types In mathematics, the integers are all of the members of this infinite set: {..., 2, 1, 0, 1, 2, 3,... }. (In mathematics, numbers such as 0.5, 2, and π are real numbers that are not integers.) C has a large collection of integer types, and has a bunch of messy and complicated rules regarding these types. In contrast to the set of integers in mathematics, the range of values for a C integer type is finite. For any given integer type, there s a minimum value, and there s a maximum value. Probably the two most frequently used integer types in C are int and char.

23 ENCM 335 Fall 2018 Slide Set 2 slide 23/56 Really, char is an integer type! It s common to think of a char variable as a container for something like a letter (A Z, a z), a digit (0 9), a punctuation mark, or a space, etc. However, to understand how C programs work, it s extremely useful to know that char is an integer type, with a relatively small range of values. The range of values for char is not the same for every C development system. The most common range is { 128, 127,..., 126, 127 } ; this is the default for C programming on Linux, macos, and Windows. The second-most common range is { 0, 1, 2,..., 254, 255 }.

24 ENCM 335 Fall 2018 Slide Set 2 slide 24/56 char variables are often used to hold character codes For example, a very common character set is ASCII the American Standard Code for Information Interchange, in which character codes 48 to 57 stand for digits 0 to 9, in that order; character codes 65 to 90 stand for letters A to Z, in that order; character codes 97 to 122 stand for letters a to z, in that order; there are various other character codes for spaces, tabs, newlines, punctuation, and so on.

25 ENCM 335 Fall 2018 Slide Set 2 slide 25/56 Most current computers use extensions of the ASCII character set ASCII is supported, along with some kind of encoding for characters that don t appear in North American English. Here s a demonstration: #include <stdio.h> int main(void) { int i; printf("c program says... "); for (i = 65; i < 68; i++) printf("%d %c ", i, i); printf("... bye from C!\n"); return 0; } What s going on with %d and %c here, and what will the program output be?

26 ENCM 335 Fall 2018 Slide Set 2 slide 26/56 Character constants These begin and end with, the single quote, character, also known as forward quote or apostrophe. Each character constant is really a convenient symbol for a number a specific code for a single character. Here are a few examples, which assume that the ASCII character set is supported: constant meaning value a code for letter a 97 B code for letter B 66 3 code for digit 3 51 { code for left brace 123 \n code for newline 10 \\ code for backslash 92

27 ENCM 335 Fall 2018 Slide Set 2 slide 27/56 Important: Do not mix up single quotes and double quotes! Double quotes are used for string constants, things like "hello", "h", and "". (Another term for string constant is string literal.) In C, a single-character string constant, say, "x", does not mean the same thing as the similar-looking character constant x. (But in the Python programming language, "x" and x do mean exactly the same thing!) Finally, don t get mixed up with the ( backtick ) character. You can t make a C character constant with a backtick at either end.

28 ENCM 335 Fall 2018 Slide Set 2 slide 28/56 Conversions between char and int In most expressions involving one or more char values, the char value(s) gets converted to int before any arithmetic or comparison takes place. Example 1. Let s describe in detail how the assignment statement works in this code fragment: char a = G, b; int c = 3; b = a + c; Example 2. Let s explain how the comparison works in this code fragment, then write out the output... char x; for (x = 48; x < 58; x++) printf("%c", x);

29 ENCM 335 Fall 2018 Slide Set 2 slide 29/56 Because arithmetic and comparisons involving char values are really done using int values, functions that receive character codes as parameters often have int parameters, not char parameters. Example: Write a definition for isdigit. This function has one parameter, called c, and its return value indicates whether or not c is a character code for a digit.

30 ENCM 335 Fall 2018 Slide Set 2 slide 30/56 Connections to ENEL 353 material Right about now, students in ENEL 353 are learning about unsigned integer systems and two s complement signed integer systems. Fact: In C on most current laptop, desktop, and server computers, the char type uses 8-bit two s complement numbers; the int type uses 32-bit two s complement numbers.

31 ENCM 335 Fall 2018 Slide Set 2 slide 31/56 Outline of Slide Set 2 An example about types, expressions, and assignment in C Expressions and operators The int and char types are both integer types Introduction to Pointers First example program with pointers Function arguments and function parameters Pointers as function parameters

32 ENCM 335 Fall 2018 Slide Set 2 slide 32/56 Introduction to Pointers The upcoming major topics in ENCM 335 are pointer types and the relationships between arrays and pointers. These topics are extremely important. You can t be an effective C programmer if you don t know them well. You also can t get a good grade in ENCM 335 if you don t know them well. The rest of Slide Set 2 will provide an introduction to pointer types. Slide Set 3 will show how pointers and arrays are related.

33 ENCM 335 Fall 2018 Slide Set 2 slide 33/56 Computer memory bits and bytes One of the key uses for main memory (the RAM circuits, not the hard drive) in a computer system is to hold data (such as variables and function parameters) belonging to running programs. The value of a bit is either 0 or 1. In a single-bit memory cell, a voltage close to ground represents a bit value of 0, and a somewhat higher voltage represents a bit value of 1. In memory systems, bits are grouped together to form bytes. In modern systems, there are 8 bits per byte; in other words, the width of a byte is 8 bits. Let s write some examples of possible values for a byte, using the ENEL 353 notation for binary numbers.

34 ENCM 335 Fall 2018 Slide Set 2 slide 34/56 Memory can be modeled as a giant array of bytes (Reminder: A model is a simplified description of a natural or engineered system; a good model helps to understand and perhaps to predict the behaviour of a system.) Each byte of memory has its own unique address, which is simply a number. The address of a byte indicates where the byte is located, not what the value of the byte is. The address space of a computer is the set of all possible addresses. Let s sketch the address space of a computer system in which memory addresses are 32 bits wide.

35 ENCM 335 Fall 2018 Slide Set 2 slide 35/56 Address spaces and memory capacity Typically, the capacity of the memory system of a computer is much smaller than the address space. Example: In 2018, a mid-range laptop has 8 GB ( 2 33 bytes) of RAM, and a 64-bit address space. What is the memory capacity expressed as a fraction of the address space size? And a typical program uses much less than the entire memory capacity of a computer. Usually a program has access to only a few relatively small regions within the address space.

36 ENCM 335 Fall 2018 Slide Set 2 slide 36/56 Memory storage of variables and function parameters If a C variable or function parameter is in memory, it is stored in a group of adjacent bytes a sequence of bytes with consecutive addresses. Let s sketch this out for some common C types, for a few different systems: 1. typical laptop, desktop or server in 2018; bit smartphone or 32-bit embedded system; 3. low-power embedded system designed for minimal battery use.

37 ENCM 335 Fall 2018 Slide Set 2 slide 37/56 General rules about sizes of types A char is always exactly 1 byte in size. For all other types, sizes vary, depending on hardware (design of processor and memory circuits), operating system, and sometimes on compiler settings. The fact that most sizes are hardware- and OS-dependent is a major headache for C developers trying to port software from one platform to another.

38 ENCM 335 Fall 2018 Slide Set 2 slide 38/56 The address of a variable The address of a variable the lowest address of all of the addresses of the bytes used for the variable. Let s illustrate that with a sketch of storage for an int variable called x. (To do this, we ll have to make up some addresses for the bytes of x.)

39 ENCM 335 Fall 2018 Slide Set 2 slide 39/56 Pointers A pointer expression is an expression that has a memory address as a value. A pointer variable is a container for a memory address. A pointer parameter is also a container for a memory address. This is a similar idea to the idea that an int variable or parameter is a container for an integer value within the range of the int type.

40 ENCM 335 Fall 2018 Slide Set 2 slide 40/56 Example pointer variable declaration int *p; (This use of * has nothing to do with multiplication.) Let s write down a couple of different ways to describe exactly what the example variable declaration means. Attention! The name of the variable here is simply p; it is not *p! The * character is part of the type information, not part of the variable name. I am not fussing unduly over a microscopic detail here trust me, getting this right really helps you to understand the use of pointer variables and parameters!

41 ENCM 335 Fall 2018 Slide Set 2 slide 41/56 Key operators related to pointer types A binary operator has two operands, but a unary operator has only one. Examples of binary and unary operators: a = b - c; // Here - is binary: subtraction. d = -e; // Here - is unary: negation. The binary * operator does multiplication. The unary * operator is called the pointer dereference operator. Dereferencing a pointer means accessing the data a pointer points to. I ll explain that with examples very soon. The unary & operator is called the address-of operator. (Use of & for address-of is unrelated to the use of & in C++ for reference types.) Let s write out a very simple example use of the address-of operator.

42 ENCM 335 Fall 2018 Slide Set 2 slide 42/56 Outline of Slide Set 2 An example about types, expressions, and assignment in C Expressions and operators The int and char types are both integer types Introduction to Pointers First example program with pointers Function arguments and function parameters Pointers as function parameters

43 ENCM 335 Fall 2018 Slide Set 2 slide 43/56 First example program with pointers In textbooks, lecture slides and notes, some program examples resemble production code software that is intended to provide useful services to people or machines. Other examples don t resemble production code at all instead, they re intended to explain programming language features in a way that is as clear and as brief as possible. The upcoming example is definitely in the second of those two categories! Let s copy the program on the next slide, make some remarks about it, and mark points 1 to 5 so we can draw some memory diagrams.

44 ENCM 335 Fall 2018 Slide Set 2 slide 44/56 #include <stdio.h> int main(void) { int j, k; int *p; p = &j; *p = 3; p = &k; *p = 7; printf("j = %d, k = %d, *p = %d.\n", j, k, *p); return 0; }

45 ENCM 335 Fall 2018 Slide Set 2 slide 45/56 Arrow notation for diagrams with pointers Writing things like addr. of j in a diagram is inconvenient, so usually we ll use blobs and arrows to indicate which addresses are contained in pointer variables and parameters. Let s redraw the diagram for point 5 in our most recent example, using arrow notation.

46 ENCM 335 Fall 2018 Slide Set 2 slide 46/56 Addresses are numbers Usually programmers don t know the exact addresses of variables, but to understand the use of pointers, it s sometimes useful to pretend that we do know those addresses. Let s make up some addresses for the bytes of p, k, and j in our most recent example, and draw yet another diagram for point 5.

47 ENCM 335 Fall 2018 Slide Set 2 slide 47/56 Outline of Slide Set 2 An example about types, expressions, and assignment in C Expressions and operators The int and char types are both integer types Introduction to Pointers First example program with pointers Function arguments and function parameters Pointers as function parameters

48 ENCM 335 Fall 2018 Slide Set 2 slide 48/56 Function arguments and function parameters #include <stdio.h> x and y are the parameters of the definition of max. The expressions a and b + 10 are arguments within the function call to max. int max(int x, int y) { return (x > y)? x : y; } int main(void) { int a = 41, b = 32, c; c = max(a, b + 10); printf("the answer is %d.\n", c); return 0; }

49 ENCM 335 Fall 2018 Slide Set 2 slide 49/56 Why is it useful to distinguish parameters from arguments? Having separate terms makes it easy to say useful things like this... The arguments in a function call are all evaluated. Each of the argument values is used to initialize the corresponding parameter value in the definition of the function being called.

50 ENCM 335 Fall 2018 Slide Set 2 slide 50/56 Terms you might see in programming literature x and y are sometimes called formal arguments of the definition of max. The expressions a and b + 10 within the function call to max are sometimes called actual arguments. #include <stdio.h> int max(int x, int y) { return (x > y)? x : y; } int main(void) { int a = 41, b = 32, c; c = max(a, b + 10); printf("the answer is %d.\n", c); return 0; }

51 ENCM 335 Fall 2018 Slide Set 2 slide 51/56 Outline of Slide Set 2 An example about types, expressions, and assignment in C Expressions and operators The int and char types are both integer types Introduction to Pointers First example program with pointers Function arguments and function parameters Pointers as function parameters

52 ENCM 335 Fall 2018 Slide Set 2 slide 52/56 Pointers as function parameters Here s an example problem: Write a C function to convert a measurement in inches only to the equivalent in in feet and inches. For example, 67 inches is 5 feet, 7 inches. Notice that the function receives one number and must communicate back two numbers. The function can t do its job simply by returning an int. The solution is given over the next two slides...

53 ENCM 335 Fall 2018 Slide Set 2 slide 53/56 #include <stdio.h> void foot_and_inch(int inch_only, int *feet, int *extra_inch); int main(void) { int total_in = 75; int ft; int in; foot_and_inch(total_in, &ft, &in); printf("%d inches is the same as %d ft, %d in.\n", total_in, ft, in); return 0; }

54 ENCM 335 Fall 2018 Slide Set 2 slide 54/56 void foot_and_inch(int inch_only, int *feet, int *extra_inch) { // point one *feet = inch_only / 12; *extra_inch = inch_only % 12; } // point two What is the program output? Let s write down a bunch of remarks, and make diagrams for point one and point two.

55 ENCM 335 Fall 2018 Slide Set 2 slide 55/56 A common mistake with pointers What if we changed main to the code on this slide? Let s make some remarks, then explain what is likely to go wrong. // Example of DEFECTIVE code! int main(void) { int total_in = 75; int *ft; int *in; foot_and_inch(total_in, ft, in); printf("%d inches is the same as %d ft, %d in.\n", total_in, *ft, *in); return 0; }

56 ENCM 335 Fall 2018 Slide Set 2 slide 56/56 A quick remark about the scanf function When scanf was introduced in a lecture, I told you that you must put &, the address-of operator, in front of the names of the variables that are to receive input. At that time, I couldn t give a very precise reason for doing so. But now you know about addresses and pointer expressions. Suppose k is a variable of type int. Why is it that the following code can t possibly work? scanf("%d", k); And what is so important about & in the following code? scanf("%d", &k);

Slide Set 3. for ENCM 339 Fall Steve Norman, PhD, PEng. Electrical & Computer Engineering Schulich School of Engineering University of Calgary

Slide Set 3. for ENCM 339 Fall Steve Norman, PhD, PEng. Electrical & Computer Engineering Schulich School of Engineering University of Calgary Slide Set 3 for ENCM 339 Fall 2016 Steve Norman, PhD, PEng Electrical & Computer Engineering Schulich School of Engineering University of Calgary September 2016 ENCM 339 Fall 2016 Slide Set 3 slide 2/46

More information

Slide Set 4. for ENCM 339 Fall 2017 Section 01. Steve Norman, PhD, PEng

Slide Set 4. for ENCM 339 Fall 2017 Section 01. Steve Norman, PhD, PEng Slide Set 4 for ENCM 339 Fall 2017 Section 01 Steve Norman, PhD, PEng Electrical & Computer Engineering Schulich School of Engineering University of Calgary September 2017 ENCM 339 Fall 2017 Section 01

More information

Slide Set 4. for ENCM 335 in Fall Steve Norman, PhD, PEng

Slide Set 4. for ENCM 335 in Fall Steve Norman, PhD, PEng Slide Set 4 for ENCM 335 in Fall 2018 Steve Norman, PhD, PEng Electrical & Computer Engineering Schulich School of Engineering University of Calgary September 2018 ENCM 335 Fall 2018 Slide Set 4 slide

More information

Slide Set 1. for ENCM 339 Fall Steve Norman, PhD, PEng. Electrical & Computer Engineering Schulich School of Engineering University of Calgary

Slide Set 1. for ENCM 339 Fall Steve Norman, PhD, PEng. Electrical & Computer Engineering Schulich School of Engineering University of Calgary Slide Set 1 for ENCM 339 Fall 2016 Steve Norman, PhD, PEng Electrical & Computer Engineering Schulich School of Engineering University of Calgary September 2016 ENCM 339 Fall 2016 Slide Set 1 slide 2/43

More information

Slide Set 3. for ENCM 339 Fall 2017 Section 01. Steve Norman, PhD, PEng

Slide Set 3. for ENCM 339 Fall 2017 Section 01. Steve Norman, PhD, PEng Slide Set 3 for ENCM 339 Fall 2017 Section 01 Steve Norman, PhD, PEng Electrical & Computer Engineering Schulich School of Engineering University of Calgary September 2017 ENCM 339 Fall 2017 Section 01

More information

Contents. Slide Set 1. About these slides. Outline of Slide Set 1. Typographical conventions: Italics. Typographical conventions. About these slides

Contents. Slide Set 1. About these slides. Outline of Slide Set 1. Typographical conventions: Italics. Typographical conventions. About these slides Slide Set 1 for ENCM 369 Winter 2014 Lecture Section 01 Steve Norman, PhD, PEng Electrical & Computer Engineering Schulich School of Engineering University of Calgary Winter Term, 2014 ENCM 369 W14 Section

More information

Slide Set 5. for ENCM 369 Winter 2014 Lecture Section 01. Steve Norman, PhD, PEng

Slide Set 5. for ENCM 369 Winter 2014 Lecture Section 01. Steve Norman, PhD, PEng Slide Set 5 for ENCM 369 Winter 2014 Lecture Section 01 Steve Norman, PhD, PEng Electrical & Computer Engineering Schulich School of Engineering University of Calgary Winter Term, 2014 ENCM 369 W14 Section

More information

Slide Set 1 (corrected)

Slide Set 1 (corrected) Slide Set 1 (corrected) for ENCM 369 Winter 2018 Section 01 Steve Norman, PhD, PEng Electrical & Computer Engineering Schulich School of Engineering University of Calgary January 2018 ENCM 369 Winter 2018

More information

Slide Set 1. for ENEL 339 Fall 2014 Lecture Section 02. Steve Norman, PhD, PEng

Slide Set 1. for ENEL 339 Fall 2014 Lecture Section 02. Steve Norman, PhD, PEng Slide Set 1 for ENEL 339 Fall 2014 Lecture Section 02 Steve Norman, PhD, PEng Electrical & Computer Engineering Schulich School of Engineering University of Calgary Fall Term, 2014 ENEL 353 F14 Section

More information

Slide Set 5. for ENCM 339 Fall Steve Norman, PhD, PEng. Electrical & Computer Engineering Schulich School of Engineering University of Calgary

Slide Set 5. for ENCM 339 Fall Steve Norman, PhD, PEng. Electrical & Computer Engineering Schulich School of Engineering University of Calgary Slide Set 5 for ENCM 339 Fall 2016 Steve Norman, PhD, PEng Electrical & Computer Engineering Schulich School of Engineering University of Calgary October 2016 ENCM 339 Fall 2016 Slide Set 5 slide 2/32

More information

Slide Set 3. for ENCM 369 Winter 2018 Section 01. Steve Norman, PhD, PEng

Slide Set 3. for ENCM 369 Winter 2018 Section 01. Steve Norman, PhD, PEng Slide Set 3 for ENCM 369 Winter 2018 Section 01 Steve Norman, PhD, PEng Electrical & Computer Engineering Schulich School of Engineering University of Calgary January 2018 ENCM 369 Winter 2018 Section

More information

Integer Multiplication and Division

Integer Multiplication and Division Integer Multiplication and Division for ENCM 369: Computer Organization Steve Norman, PhD, PEng Electrical & Computer Engineering Schulich School of Engineering University of Calgary Winter Term, 208 Integer

More information

Slide Set 8. for ENCM 339 Fall 2017 Section 01. Steve Norman, PhD, PEng

Slide Set 8. for ENCM 339 Fall 2017 Section 01. Steve Norman, PhD, PEng Slide Set 8 for ENCM 339 Fall 2017 Section 01 Steve Norman, PhD, PEng Electrical & Computer Engineering Schulich School of Engineering University of Calgary October 2017 ENCM 339 Fall 2017 Section 01 Slide

More information

CS102: Variables and Expressions

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

More information

Slide Set 9. for ENCM 335 in Fall Steve Norman, PhD, PEng

Slide Set 9. for ENCM 335 in Fall Steve Norman, PhD, PEng Slide Set 9 for ENCM 335 in Fall 2018 Steve Norman, PhD, PEng Electrical & Computer Engineering Schulich School of Engineering University of Calgary October 2018 ENCM 335 Fall 2018 Slide Set 9 slide 2/32

More information

Slide Set 11. for ENCM 369 Winter 2015 Lecture Section 01. Steve Norman, PhD, PEng

Slide Set 11. for ENCM 369 Winter 2015 Lecture Section 01. Steve Norman, PhD, PEng Slide Set 11 for ENCM 369 Winter 2015 Lecture Section 01 Steve Norman, PhD, PEng Electrical & Computer Engineering Schulich School of Engineering University of Calgary Winter Term, 2015 ENCM 369 W15 Section

More information

T02 Tutorial Slides for Week 2

T02 Tutorial Slides for Week 2 T02 Tutorial Slides for Week 2 ENEL 353: Digital Circuits Fall 2017 Term Steve Norman, PhD, PEng Electrical & Computer Engineering Schulich School of Engineering University of Calgary 19 September, 2017

More information

ENCM 335 Fall 2018 Lab 2 for the Week of September 24

ENCM 335 Fall 2018 Lab 2 for the Week of September 24 page 1 of 8 ENCM 335 Fall 2018 Lab 2 for the Week of September 24 Steve Norman Department of Electrical & Computer Engineering University of Calgary September 2018 Lab instructions and other documents

More information

Fundamental of Programming (C)

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

More information

Slide Set 4. for ENCM 369 Winter 2018 Section 01. Steve Norman, PhD, PEng

Slide Set 4. for ENCM 369 Winter 2018 Section 01. Steve Norman, PhD, PEng Slide Set 4 for ENCM 369 Winter 2018 Section 01 Steve Norman, PhD, PEng Electrical & Computer Engineering Schulich School of Engineering University of Calgary January 2018 ENCM 369 Winter 2018 Section

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

Slide Set 5. for ENCM 369 Winter 2018 Section 01. Steve Norman, PhD, PEng

Slide Set 5. for ENCM 369 Winter 2018 Section 01. Steve Norman, PhD, PEng Slide Set 5 for ENCM 369 Winter 2018 Section 01 Steve Norman, PhD, PEng Electrical & Computer Engineering Schulich School of Engineering University of Calgary February 2018 ENCM 369 Winter 2018 Section

More information

Slide Set 6. for ENCM 339 Fall 2017 Section 01. Steve Norman, PhD, PEng

Slide Set 6. for ENCM 339 Fall 2017 Section 01. Steve Norman, PhD, PEng Slide Set 6 for ENCM 339 Fall 2017 Section 01 Steve Norman, PhD, PEng Electrical & Computer Engineering Schulich School of Engineering University of Calgary October 2017 ENCM 339 Fall 2017 Section 01 Slide

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

Slide Set 1. for ENEL 353 Fall Steve Norman, PhD, PEng. Electrical & Computer Engineering Schulich School of Engineering University of Calgary

Slide Set 1. for ENEL 353 Fall Steve Norman, PhD, PEng. Electrical & Computer Engineering Schulich School of Engineering University of Calgary Slide Set 1 for ENEL 353 Fall 2017 Steve Norman, PhD, PEng Electrical & Computer Engineering Schulich School of Engineering University of Calgary Fall Term, 2017 SN s ENEL 353 Fall 2017 Slide Set 1 slide

More information

Contents Slide Set 9. Final Notes on Textbook Chapter 7. Outline of Slide Set 9. More about skipped sections in Chapter 7. Outline of Slide Set 9

Contents Slide Set 9. Final Notes on Textbook Chapter 7. Outline of Slide Set 9. More about skipped sections in Chapter 7. Outline of Slide Set 9 slide 2/41 Contents Slide Set 9 for ENCM 369 Winter 2014 Lecture Section 01 Steve Norman, PhD, PEng Electrical & Computer Engineering Schulich School of Engineering University of Calgary Winter Term, 2014

More information

CSE 1001 Fundamentals of Software Development 1. Identifiers, Variables, and Data Types Dr. H. Crawford Fall 2018

CSE 1001 Fundamentals of Software Development 1. Identifiers, Variables, and Data Types Dr. H. Crawford Fall 2018 CSE 1001 Fundamentals of Software Development 1 Identifiers, Variables, and Data Types Dr. H. Crawford Fall 2018 Identifiers, Variables and Data Types Reserved Words Identifiers in C Variables and Values

More information

Lecture 3. More About C

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

More information

Slide Set 9. for ENCM 369 Winter 2018 Section 01. Steve Norman, PhD, PEng

Slide Set 9. for ENCM 369 Winter 2018 Section 01. Steve Norman, PhD, PEng Slide Set 9 for ENCM 369 Winter 2018 Section 01 Steve Norman, PhD, PEng Electrical & Computer Engineering Schulich School of Engineering University of Calgary March 2018 ENCM 369 Winter 2018 Section 01

More information

Slide Set 8. for ENCM 369 Winter 2018 Section 01. Steve Norman, PhD, PEng

Slide Set 8. for ENCM 369 Winter 2018 Section 01. Steve Norman, PhD, PEng Slide Set 8 for ENCM 369 Winter 2018 Section 01 Steve Norman, PhD, PEng Electrical & Computer Engineering Schulich School of Engineering University of Calgary March 2018 ENCM 369 Winter 2018 Section 01

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

THE FUNDAMENTAL DATA TYPES

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

More information

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

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

More information

Goals of this Lecture

Goals of this Lecture C Pointers Goals of this Lecture Help you learn about: Pointers and application Pointer variables Operators & relation to arrays 2 Pointer Variables The first step in understanding pointers is visualizing

More information

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

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

More information

Course Outline Introduction to C-Programming

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

More information

Slide Set 15 (Complete)

Slide Set 15 (Complete) Slide Set 15 (Complete) for ENCM 339 Fall 2017 Section 01 Steve Norman, PhD, PEng Electrical & Computer Engineering Schulich School of Engineering University of Calgary November 2017 ENCM 339 Fall 2017

More information

More about Binary 9/6/2016

More about Binary 9/6/2016 More about Binary 9/6/2016 Unsigned vs. Two s Complement 8-bit example: 1 1 0 0 0 0 1 1 2 7 +2 6 + 2 1 +2 0 = 128+64+2+1 = 195-2 7 +2 6 + 2 1 +2 0 = -128+64+2+1 = -61 Why does two s complement work this

More information

Chapter 3. Fundamental Data Types

Chapter 3. Fundamental Data Types Chapter 3. Fundamental Data Types Byoung-Tak Zhang TA: Hanock Kwak Biointelligence Laboratory School of Computer Science and Engineering Seoul National Univertisy http://bi.snu.ac.kr Variable Declaration

More information

ENCM 369 Winter 2019 Lab 6 for the Week of February 25

ENCM 369 Winter 2019 Lab 6 for the Week of February 25 page of ENCM 369 Winter 29 Lab 6 for the Week of February 25 Steve Norman Department of Electrical & Computer Engineering University of Calgary February 29 Lab instructions and other documents for ENCM

More information

Introduction to C. Systems Programming Concepts

Introduction to C. Systems Programming Concepts Introduction to C Systems Programming Concepts Introduction to C A simple C Program Variable Declarations printf ( ) Compiling and Running a C Program Sizeof Program #include What is True in C? if example

More information

Will introduce various operators supported by C language Identify supported operations Present some of terms characterizing operators

Will 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 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

Structures, Operators

Structures, 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 information

Fundamentals of Programming

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

More information

Programming for Engineers Introduction to C

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

More information

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

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

More information

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

Chapter 12 Variables and Operators

Chapter 12 Variables and Operators Chapter 12 Variables and Operators Highlights (1) r. height width operator area = 3.14 * r *r + width * height literal/constant variable expression (assignment) statement 12-2 Highlights (2) r. height

More information

Chapter 7. Basic Types

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

More information

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

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

More information

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

Fundamentals of Programming Session 4

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

More information

DECLARAING AND INITIALIZING POINTERS

DECLARAING AND INITIALIZING POINTERS DECLARAING AND INITIALIZING POINTERS Passing arguments Call by Address Introduction to Pointers Within the computer s memory, every stored data item occupies one or more contiguous memory cells (i.e.,

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

Reserved Words and Identifiers

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

More information

Bits, Words, and Integers

Bits, Words, and Integers Computer Science 52 Bits, Words, and Integers Spring Semester, 2017 In this document, we look at how bits are organized into meaningful data. In particular, we will see the details of how integers are

More information

Data Types. Data Types. Integer Types. Signed Integers

Data Types. Data Types. Integer Types. Signed Integers Data Types Data Types Dr. TGI Fernando 1 2 The fundamental building blocks of any programming language. What is a data type? A data type is a set of values and a set of operations define on these values.

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

1/25/2018. ECE 220: Computer Systems & Programming. Write Output Using printf. Use Backslash to Include Special ASCII Characters

1/25/2018. ECE 220: Computer Systems & Programming. Write Output Using printf. Use Backslash to Include Special ASCII Characters University of Illinois at Urbana-Champaign Dept. of Electrical and Computer Engineering ECE 220: Computer Systems & Programming Review: Basic I/O in C Allowing Input from the Keyboard, Output to the Monitor

More information

ENCM 501 Winter 2015 Tutorial for Week 5

ENCM 501 Winter 2015 Tutorial for Week 5 ENCM 501 Winter 2015 Tutorial for Week 5 Steve Norman, PhD, PEng Electrical & Computer Engineering Schulich School of Engineering University of Calgary 11 February, 2015 ENCM 501 Tutorial 11 Feb 2015 slide

More information

A flow chart is a graphical or symbolic representation of a process.

A 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 information

CS 31: Intro to Systems Binary Arithmetic. Martin Gagné Swarthmore College January 24, 2016

CS 31: Intro to Systems Binary Arithmetic. Martin Gagné Swarthmore College January 24, 2016 CS 31: Intro to Systems Binary Arithmetic Martin Gagné Swarthmore College January 24, 2016 Unsigned Integers Suppose we had one byte Can represent 2 8 (256) values If unsigned (strictly non-negative):

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

Objects and Types. COMS W1007 Introduction to Computer Science. Christopher Conway 29 May 2003

Objects and Types. COMS W1007 Introduction to Computer Science. Christopher Conway 29 May 2003 Objects and Types COMS W1007 Introduction to Computer Science Christopher Conway 29 May 2003 Java Programs A Java program contains at least one class definition. public class Hello { public static void

More information

A Java program contains at least one class definition.

A Java program contains at least one class definition. Java Programs Identifiers Objects and Types COMS W1007 Introduction to Computer Science Christopher Conway 29 May 2003 A Java program contains at least one class definition. public class Hello { public

More information

Introduction to Programming in C Department of Computer Science and Engineering. Lecture No. #44. Multidimensional Array and pointers

Introduction to Programming in C Department of Computer Science and Engineering. Lecture No. #44. Multidimensional Array and pointers Introduction to Programming in C Department of Computer Science and Engineering Lecture No. #44 Multidimensional Array and pointers In this video, we will look at the relation between Multi-dimensional

More information

COMP26120: Pointers in C (2018/19) Lucas Cordeiro

COMP26120: Pointers in C (2018/19) Lucas Cordeiro COMP26120: Pointers in C (2018/19) Lucas Cordeiro lucas.cordeiro@manchester.ac.uk Organisation Lucas Cordeiro (Senior Lecturer, FM Group) lucas.cordeiro@manchester.ac.uk Office: 2.44 Office hours: 10-11

More information

ENCM 335 Fall 2018 Lab 6 for the Week of October 22 Complete Instructions

ENCM 335 Fall 2018 Lab 6 for the Week of October 22 Complete Instructions page 1 of 5 ENCM 335 Fall 2018 Lab 6 for the Week of October 22 Complete Instructions Steve Norman Department of Electrical & Computer Engineering University of Calgary October 2018 Lab instructions and

More information

Display Input and Output (I/O)

Display Input and Output (I/O) 2000 UW CSE CSE / ENGR 142 Programming I isplay Input and Output (I/O) -1 Writing Useful Programs It s hard to write useful programs using only variables and assignment statements Even our Fahrenheit to

More information

Operators in C. Staff Incharge: S.Sasirekha

Operators 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 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

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

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

More information

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

Slides for Lecture 15

Slides for Lecture 15 Slides for Lecture 15 ENCM 501: Principles of Computer Architecture Winter 2014 Term Steve Norman, PhD, PEng Electrical & Computer Engineering Schulich School of Engineering University of Calgary 6 March,

More information

3. EXPRESSIONS. It is a sequence of operands and operators that reduce to a single value.

3. EXPRESSIONS. It is a sequence of operands and operators that reduce to a single value. 3. EXPRESSIONS It is a sequence of operands and operators that reduce to a single value. Operator : It is a symbolic token that represents an action to be taken. Ex: * is an multiplication operator. Operand:

More information

Contents. Slide Set 2. Outline of Slide Set 2. More about Pseudoinstructions. Avoid using pseudoinstructions in ENCM 369 labs

Contents. Slide Set 2. Outline of Slide Set 2. More about Pseudoinstructions. Avoid using pseudoinstructions in ENCM 369 labs Slide Set 2 for ENCM 369 Winter 2014 Lecture Section 01 Steve Norman, PhD, PEng Electrical & Computer Engineering Schulich School of Engineering University of Calgary Winter Term, 2014 ENCM 369 W14 Section

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

Slides for Lecture 15

Slides for Lecture 15 Slides for Lecture 5 ENEL 353: Digital Circuits Fall 203 Term Steve Norman, PhD, PEng Electrical & Computer Engineering Schulich School of Engineering University of Calgary October, 203 ENEL 353 F3 Section

More information

ENCM 335 Fall 2018 Tutorial for Week 13

ENCM 335 Fall 2018 Tutorial for Week 13 ENCM 335 Fall 2018 Tutorial for Week 13 Steve Norman, PhD, PEng Electrical & Computer Engineering Schulich School of Engineering University of Calgary 06 December, 2018 ENCM 335 Tutorial 06 Dec 2018 slide

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

Data Types and Variables in C language

Data 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 information

cast int( x float( x str( x hex( int string int oct( int string int bin( int string int chr( int int ord( ch

cast int( x float( x str( x hex( int string int oct( int string int bin( int string int chr( int int ord( ch More About Values Casts To cast is to take a value of one type and return the corresponding value of some other type (or an error, if the cast is impossible) int(x) casts a string, float, or boolean x

More information

Outline. Performing Computations. Outline (cont) Expressions in C. Some Expression Formats. Types for Operands

Outline. Performing Computations. Outline (cont) Expressions in C. Some Expression Formats. Types for Operands Performing Computations C provides operators that can be applied to calculate expressions: tax is 8.5% of the total sale expression: tax = 0.085 * totalsale Need to specify what operations are legal, how

More information

Full file at

Full file at Java Programming: From Problem Analysis to Program Design, 3 rd Edition 2-1 Chapter 2 Basic Elements of Java At a Glance Instructor s Manual Table of Contents Overview Objectives s Quick Quizzes Class

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

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

Computers Programming Course 6. Iulian Năstac

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

More information

2. MACHINE REPRESENTATION OF TYPICAL ARITHMETIC DATA FORMATS (NATURAL AND INTEGER NUMBERS).

2. MACHINE REPRESENTATION OF TYPICAL ARITHMETIC DATA FORMATS (NATURAL AND INTEGER NUMBERS). 2. MACHINE REPRESENTATION OF TYPICAL ARITHMETIC DATA FORMATS (NATURAL AND INTEGER NUMBERS). 2.. Natural Binary Code (NBC). The positional code with base 2 (B=2), introduced in Exercise, is used to encode

More information

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

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

More information

ENCM 339 Fall 2017 Lecture Section 01 Lab 3 for the Week of October 2

ENCM 339 Fall 2017 Lecture Section 01 Lab 3 for the Week of October 2 page 1 of 11 ENCM 339 Fall 2017 Lecture Section 01 Lab 3 for the Week of October 2 Steve Norman Department of Electrical & Computer Engineering University of Calgary September 2017 Lab instructions and

More information

GO - OPERATORS. This tutorial will explain the arithmetic, relational, logical, bitwise, assignment and other operators one by one.

GO - OPERATORS. This tutorial will explain the arithmetic, relational, logical, bitwise, assignment and other operators one by one. http://www.tutorialspoint.com/go/go_operators.htm GO - OPERATORS Copyright tutorialspoint.com An operator is a symbol that tells the compiler to perform specific mathematical or logical manipulations.

More information

3. Types of Algorithmic and Program Instructions

3. 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 information

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

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

More information

CPE 101, reusing/mod slides from a UW course (used by permission) Lecture 5: Input and Output (I/O)

CPE 101, reusing/mod slides from a UW course (used by permission) Lecture 5: Input and Output (I/O) CPE 101, reusing/mod slides from a UW course (used by permission) Lecture 5: Input and Output (I/O) Overview (5) Topics Output: printf Input: scanf Basic format codes More on initializing variables 2000

More information

Topic Notes: Bits and Bytes and Numbers

Topic Notes: Bits and Bytes and Numbers Computer Science 220 Assembly Language & Comp Architecture Siena College Fall 2010 Topic Notes: Bits and Bytes and Numbers Binary Basics At least some of this will be review, but we will go over it for

More information

Declaration and Memory

Declaration and Memory Declaration and Memory With the declaration int width; the compiler will set aside a 4-byte (32-bit) block of memory (see right) The compiler has a symbol table, which will have an entry such as Identifier

More information

7/8/10 KEY CONCEPTS. Problem COMP 10 EXPLORING COMPUTER SCIENCE. Algorithm. Lecture 2 Variables, Types, and Programs. Program PROBLEM SOLVING

7/8/10 KEY CONCEPTS. Problem COMP 10 EXPLORING COMPUTER SCIENCE. Algorithm. Lecture 2 Variables, Types, and Programs. Program PROBLEM SOLVING KEY CONCEPTS COMP 10 EXPLORING COMPUTER SCIENCE Lecture 2 Variables, Types, and Programs Problem Definition of task to be performed (by a computer) Algorithm A particular sequence of steps that will solve

More information

Arithmetic Expressions in C

Arithmetic Expressions in C Arithmetic Expressions in C Arithmetic Expressions consist of numeric literals, arithmetic operators, and numeric variables. They simplify to a single value, when evaluated. Here is an example of an arithmetic

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