CECS 130 Mid-term Test Review

Size: px
Start display at page:

Download "CECS 130 Mid-term Test Review"

Transcription

1 CECS 130 Mid-term Test Review Provided by REACH Resources for Academic Achievement Presenter: A REACH Tutor REACH

2 Content on the Mid-term Exam ochapters 1-10 from C Programming for the Absolute Beginner, Second Edition by Michael Vine

3 So, we will be covering: Data types Pointers Conditions Strings Loops Data Structures Functions Dynamic Memory Arrays

4 Variable Types Data Type Description Declaration Example Integer Floatingpoint number Whole numbers, positive or negative All numbers, positive or negative, decimals and fractions int x = ; -3, 0, 3, 29 float x = ; , 0.00, Character Representations of integer values known as character codes char x = ; m, M, * To declare a constant (read only) value: const int x = 20; const float PI = 3.14;

5 Variable Types TYPE SIZE VALUES bool 1 byte true (1) or false (0) char 1 byte a to z, A to Z, 0 to 9, space, tab, etc. int 4 bytes -2,147,483,648 to 2,147,483,647 short 2 bytes -32,768 to 32,767 long 4 bytes -2,147,483,648 to 2,147,483,647 float 4 bytes + - (1.2 x 10^-38 to 3.4 x 10^38) double 8 bytes +- (2.3 x 10^-308 to -1.7 x 10^308)

6 Printf( ) ; Scanf( ) ; Can you explain what the code is doing? 1 #include <stdio.h> 2 3 int main() 4 { 5 int this_is_a_number = 0; 6 7 printf( Please enter a number: ); 8 scanf( %d, &this_is_a_number ); 9 printf( \nyou entered %d, this_is_a_number ); 10 getchar(); return 0; 13

7 Conversion Specifiers Character - %c Integer - %d Float (decimal)- %f String - %s Printf Format Tags: Format: %[flags][width][.precision][length]specifier Example: %[.precision]specifier 7 float fboat = ; 8 printf( %.2f, %.3f, %.5f, boat, boat, boat ); Output: 12.12, ,

8 Can you predict the printout? 1 int main() 2 { 3 printf( %c%c\n, a,65); 4 printf( %10d\n,1997); 5 printf( %010d\n, 1997); 6 printf( floats: %4.2f \n, ); 7 printf( %s\n, A string ); 8 printf( %f\n, 55.55); 9 return 0; 10

9 Can you predict the printout? 1 int main() 2 { 3 printf( %c%c\n, a,65); 4 printf( %10d\n,1997); 5 printf( %010d\n, 1997); 6 printf( floats: %4.2f \n, ); 7 printf( %s\n, A string ); 8 printf( %f, 55.55); Output: aa floats: 3.14 A string return 0; 10

10 Scanf( ); Conversion Specifies Description %d Receives integer value %f Receives floating-point number %c Receives character

11 Predict the printout: User enters 2 and 4 : 1 #include <stdio.h> 2 3 int main() 4 { Output: Please enter first number: 2 Enter second number: 4 The result is 5. 5 int inum_1= 0; 6 int inum_2= 0; 7 8 printf( Please enter first number: ); 9 scanf( %d, &inum_1 ); 10 printf( \nenter second number: ); 11 scanf( %d, &inum_2 ); 12 printf( \n\nthe result is %d. \n, 24 / (inum_1 * inum_2) + 6 / 3); return 0; 15

12 Predict the printout: User enters 2 and 4 : 1 #include <stdio.h> 2 3 int main() 4 { Output: Please enter first number: 2 Enter second number: 4 The result is 5. 5 int inum_1= 0; 6 int inum_2= 0; 7 8 printf( Please enter first number: ); 9 scanf( %d, &inum_1 ); 10 printf( \nenter second number: ); 11 scanf( %d, &inum_2 ); 12 printf( \n\nthe result is %d. \n, 24 / (inum_1 * inum_2) + 6 / 3); return 0; 15

13 Arithmetic and Order of Precedence Operator Description * Multiplication / Division % Modulus (remainder) + Addition - Subtraction Order of Precedence Description ( ) Parentheses are evaluated first, from innermost to outermost *, /, % Evaluated second, from Left to Right +, - Evaluated last, from Left to Right

14 Can you predict the printout? Output: 1 #include <stdio.h> 2 3 int main() 4 { 5 int x = 0; 6 int y = 0; 7 int result1, result2; The result is result1 = y/x; 10 result2 = y%x; printf( \n\nthe result is %d.%d \n, result1, 25 * result2); 13

15 Can you predict the printout? Output: 1 #include <stdio.h> 2 3 int main() 4 { 5 int x = 0; 6 int y = 0; 7 int result1, result2; The result is result1 = y/x; 10 result2 = y%x; printf( \n\nthe result is %d.%d \n, result1, 25 * result2); 13

16 Conditions and Operators Operator Description == Equal to!= Not Equal > Greater Than < Less Than >= Greater Than or Equal to Order of Precedence Description && AND condition OR condition

17 Comparisons > greater than 5 > 4 is TRUE < less than 4 < 5 is TRUE >= greater than or equal 4 >= 4 is TRUE <= less than or equal 3 <= 4 is TRUE == equal to 5 == 5 is TRUE!= not equal to 5!= 4 is TRUE

18 Boolean Operators Do you know the answer to these? A.!( 1 0 ) B.!( 1 1&& 0 ) C.!(( 1 0 ) && 0) =!( 1 ) = 0 =!( 1 0 ) = 0 =!(1 && 0) =!0 = 1

19 Boolean Operators Do you know the answer to these? A.!( 1 0 ) B.!( 1 1&& 0 ) C.!(( 1 0 ) && 0) =!( 1 ) = 0 =!( 1 0 ) = 0 =!(1 && 0) =!0 = 1

20 Quiz Using if-statements, write a program that will ask a user to enter a number 1, 2, or 3, and print out the following: User Input Printout 1 Smitty Werbenjagermanjensen was Number 1. 2 Fool me 2 times, can t put the blame on you. 3 Gimme 3 steps.

21 Possible Answer : 1 #include <stdio.h> 2 int main() { 4 printf( Enter one of the following: %d, %d, or %d\n,1,2,3 ); 5 scanf( %d, &a ); 6 if(a==1 a==2 a==3) { 7 if(a==1){ 8 printf( \nsmitty Werbenjagermanjensen was Number %d.\n, 1); 9 10 if(a==2){ 11 printf( \nfool me %d times, can t put the blame on you.\n, 2); if(a==3){ 11 printf( \ngimme %d steps.\n, 3); else 17 printf( Sorry, you entered an invalid value\n ); 18 return 0;

22 Switch-Case Statement 1 switch ( <var> ) 2 { 3 case <this-value>: 4 code to execute if <var> == this-value; 5 break; 6 case <that-value>: 7 code to execute if <var> == that-value; 8 break; default: 11 code executed if <var> does not equal any of the values; 12 break; 13

23 Loops while ( condition ) { Code to execute while the condition is true Quiz: Can you write a program that prints x while x increments from 0 to 10?

24 Possible Answer : 1 #include <stdio.h> 2 int main() 3 { 4 int x = 0; 5 6 while ( x < 10 ) 7 { 8 printf( %d, x ); 9 x++; 10 printf( \nfool me %d times, can t put the blame on you.\n, 2); getchar(); 13

25 For Loop Often used when the # of iterations is already known. Contains 3 separate expressions: 1. Variable initialization 2. Conditional expression 3. Increment/Decrement Write a program with a for loop that counts down from 10.

26 Possible Answer : 1 #include <stdio.h> 2 3 int main() 4 { 5 int x = 0; 6 for( x=10; x>=0; x-- ) 7 { 8 printf( %d\n, x ); system( pause ); 12

27 Break/Continue Statements break; Used to exit a loop. Once this statement is executed the program will execute the statement immediately following the end of the loop. continue; Used to manipulate program flow in a loop. When executed, any remaining statements in the loop will be skipped and the next iteration of the loop will begin.

28 Function Prototypes & Definitions Function Prototype Syntax return-type function_name ( arg_type arg1,..., arg_type argn ) Function Prototypes tell you the data type returned by the function, the data type of parameters, how many parameters, and the order of parameters. Function definitions implement the function prototype Where are function prototypes located in the program? Where do you find function definitions?

29 Function Prototypes & Definitions Where are function prototypes located in the program? Answer: before the main( ) { function. Where do you find function definitions? Answer: function definitions are self-contained outside of the main( ) { function, usually written below it.

30 Calling Functions #include <stdio.h> int mult ( int x, int y ); // function prototype int main() { int x; int y; printf( "Please input two numbers to be multiplied: " ); scanf( "%d", &x ); scanf( "%d", &y ); printf( "The product of your two numbers is %d\n", mult( x, y ) ); getchar(); return 0; int mult (int x, int y) //function definition { return x * y;

31 Declaring a 1-D Array Can you declare a one-dimensional array made up of 10 integers? Answer: int iarray[10] How to declare an Array: int iarray[10]; float faverages[30]; double dresults[3]; short ssalaries [9]; char cname[19]; // 18 characters and 1 null character

32 Declaring a 1-D Array Why do we initialize? Because memory spaces may not be cleared from previous values when arrays are created. Can initialize an array directly. Example: int iarray[5]={0,1,2,3,4; Can initialize an array with a loop such as FOR( )

33 Initializing a 1-D Array with a for( ) loop #include <stdio.h> main() { int x; int iarray[5]; for( x=0; x < 5 ; x++) { iarray[x] = 0;

34 Initializing a 1-D Array with a for( ) loop Now add printing: #include <stdio.h> main() { int x; int iarray[5]; for( x=0; x < 5 ; x++ ) { iarray[x] = 0; for( x=0 ; x<5; x++ ) { printf( \n iarray[%d] = %d \n, x, iarray[x] );

35 Searching an array #include <stdio.h> main() { int x; int ivalue; int ifound = -1; int iarray[5]; // initialize the array for( x=0; x < 5 ; x++) { iarray[x] = (x+x); printf( \n Enter value to search for: ); scanf( %d, &ivalue); // search for number for(x=0 ; x<5; x++) { if( iarray[x] ==ivalue){ ifound = x; break; if(ifound >-1) printf( \n I found your search value in element %d \n, ifound); else printf( \n Sorry, your search value was not found \n );

36 Pointers Pointer variables, simply called pointers, are designed to hold memory addresses as their values. Normally, a variable contains a specific value, e.g., an integer, a floating-point value, or a character. However, a pointer contains the memory address of a variable that in turn contains a specific value.

37 Pointers int val = 5; int *val_ptr = &val; val *val_ptr 5 0x3F 0x3F 0x83

38 Pointer Syntax datatype *pointer_name = &variable_name; OR datatype *pointer_name = NULL; OR datatype *pointer_name = 0; It s important to initialize pointers to prevent fatal runtime errors or accidentally modifying important data.

39 Pointers When an ampersand (&) is prefixed to a variable name, it refers to the memory address of this variable. val *val_ptr 5 0x3F &val = 0x3F &val_ptr = 0x83

40 Ampersand example #include <stdio.h> int main() { char somechar = 'x'; printf( %p\n", &somechar); system("pause"); return 0; Output: 0022FF47

41 Passing variables by value void exchange(int x, int y); main() { int a = 5; int b = 3; exchange(a,b); [print a and b] void exchange(int x, int y); { [print x and y] int temp = x; int x = y; int y = temp; [print x and y]

42 Passing variables by value void exchange(int x, int y); main() { int a = 5; int b = 3; exchange(a,b); [print a and b] void exchange(int x, int y); { [print x and y] int temp = x; int x = y; int y = temp; [print x and y] Output: x = 5, y = 3 x = 3, y = 5 a = 5, b = 3

43 Passing variables with pointers void exchange(int*, int*); main() { int a = 5; int b = 3; exchange(&a,&b); [print a and b] void exchange(int *x, int *y); { [print *x and *y] int temp = *i; int *x = *y; int *y = temp; [print *x and *y]

44 Passing variables with pointers void exchange(int*, int*); main() { int a = 5; int b = 3; exchange(&a,&b); [print a and b] void exchange(int *x, int *y); { [print *x and *y] int temp = *i; int *x = *y; int *y = temp; [print *x and *y] Output: *x = 5, *y = 3 *x = 3, *y = 5 a = 3, b = 5

45 Pointers Pointing to Pointers int val = 5; int *val_ptr = &val; int **val_ptr_ptr = &val_ptr; val *val_ptr **val_ptr_ptr 5 0x3F 0x83 &val = 0x3F &val_ptr = 0x83 &val_ptr_ptr = 0xF5

46 Pointers Pointing to Pointers val = 5 *val_ptr = 5 **val_ptr_ptr = 5 **val_ptr_ptr = *val_ptr = val = 5 *val_ptr_ptr = val_ptr = &val = 0x3F val_ptr_ptr = &val_ptr = 0x83 &val_ptr_ptr = 0xF5 val *val_ptr **val_ptr_ptr 5 0x3F 0x83 &val = 0x3F &val_ptr = 0x83 &val_ptr_ptr = 0xF5

47 Pointers to Arrays An array variable without a bracket and a subscript actually represents the starting address of the array. An array variable is essentially a pointer. Suppose you declare an array of int value as follows: int list[6] = {11, 12, 13, 14, 15, 16; *(list + 1) is different from *list + 1. The dereference operator (*) has precedence over +. So, *list + 1 adds 1 to the value of the first element in the array, while *(list + 1) dereferences the element at address (list + 1) in the array.

48 Pointers to Arrays main() { int list[3] = {1, 0, 5; int k = 0; main() { int list[3] = {1, 0, 5; int k = 0; k = *list + 1; k = *(list + 1); [print k] [print k]

49 Pointers to Arrays main() { int list[3] = {1, 0, 5; int k = 0; main() { int list[3] = {1, 0, 5; int k = 0; k = *list + 1; k = *(list + 1); [print k] [print k] Output: k = 2 Output: k = 0

50 Strings Function strlen() Description Returns numeric string length up to, but not including null character tolower() and toupper() Converts a single character to upper or lower case strcpy() strcat() strcmp() strstr() Copies the contents of one string into another string Appends one string onto the end of another Compares two strings for equality Searches the first string for the first occurrence of the second string

51 Strings #include <stdio.h> #include <string.h> main() { char *str1 = REACH ; char str2[] = Tutoring ; printf( \nthe length of string 1 is %d \n, strlen(str1)); printf( The length of string 2 is %d\n,strlen(str2));

52 Strings #include <stdio.h> #include <string.h> main() { char *str1 = REACH ; char str2[] = Tutoring ; printf( \nthe length of string 1 is %d \n, strlen(str1)); printf( The length of string 2 is %d\n,strlen(str2)); Output: The length of string 1 is 5 The length of string 2 is 8

53 Strings #include <stdio.h> #include <string.h> void convertl(char *); main() { char name1[] = Barbara Bush ; convertl(name1); void convertl(char *str) { int x; for ( x = 0; x <=strlen(str) ; x++) str[x] = tolower(str[x]); printf( \nthe name in l.c. is %s\n, str);

54 Strings #include <stdio.h> #include <string.h> void convertl(char *); Output: main() { char name1[] = Barbara Bush ; convertl(name1); The name in l.c. is barbarabush void convertl(char *str) { int x; for ( x = 0; x <=strlen(str) ; x++) str[x] = tolower(str[x]); printf( \nthe name in l.c. is %s\n, str);

55 Data Structures Arrays require that all elements be of the same data type. Many times it is necessary to group information of different data types. An example is a list of materials for a product. The list typically includes a name for each item, a part number, dimensions, weight, and cost. C and C++ support data structures that can store combinations of character, integer floating point and enumerated type data. They are called - structs.

56 Structure Syntax struct my_example { int assignment; char grade; char name[20]; mystruct; mystruct students[3]; stu1.assignment = 3; stu1.grade = A ; stu1.name = Patrick ;

57 Thank you! This presentation was provided by REACH Resources for Academic Achievement

Sources: On the Web: Slides will be available on:

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 information

arrays C Programming Language - Arrays

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

Keywords are identifiers having predefined meanings in C programming language. The list of keywords used in standard C are : unsigned void

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

ASCII Encoding. The char Type. Manipulating Characters. Manipulating Characters

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

Embedded Systems. Review of ANSI C Topics. A Review of ANSI C and Considerations for Embedded C Programming. Basic features of C

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

5 Arrays and Pointers

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

The C Programming Language course syllabus associate level

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

Stacks. Linear data structures

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

Informatica e Sistemi in Tempo Reale

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

Introduction to Java

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

Name: Class: Date: 9. The compiler ignores all comments they are there strictly for the convenience of anyone reading the program.

Name: 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 information

MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question.

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

Java Basics: Data Types, Variables, and Loops

Java Basics: Data Types, Variables, and Loops Java Basics: Data Types, Variables, and Loops If debugging is the process of removing software bugs, then programming must be the process of putting them in. - Edsger Dijkstra Plan for the Day Variables

More information

Chapter 2: Elements of Java

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

Molecular Dynamics Simulations with Applications in Soft Matter Handout 7 Memory Diagram of a Struct

Molecular Dynamics Simulations with Applications in Soft Matter Handout 7 Memory Diagram of a Struct Dr. Martin O. Steinhauser University of Basel Graduate Lecture Spring Semester 2014 Molecular Dynamics Simulations with Applications in Soft Matter Handout 7 Memory Diagram of a Struct Friday, 7 th March

More information

Chapter 2 Introduction to Java programming

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

KITES TECHNOLOGY COURSE MODULE (C, C++, DS)

KITES TECHNOLOGY COURSE MODULE (C, C++, DS) KITES TECHNOLOGY 360 Degree Solution www.kitestechnology.com/academy.php info@kitestechnology.com technologykites@gmail.com Contact: - 8961334776 9433759247 9830639522.NET JAVA WEB DESIGN PHP SQL, PL/SQL

More information

About The Tutorial. Audience. Prerequisites. Copyright & Disclaimer

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

Simple C++ Programs. Engineering Problem Solving with C++, Etter/Ingber. Dev-C++ Dev-C++ Windows Friendly Exit. The C++ Programming Language

Simple C++ Programs. Engineering Problem Solving with C++, Etter/Ingber. Dev-C++ Dev-C++ Windows Friendly Exit. The C++ Programming Language Simple C++ Programs Engineering Problem Solving with C++, Etter/Ingber Chapter 2 Simple C++ Programs Program Structure Constants and Variables C++ Operators Standard Input and Output Basic Functions from

More information

Introduction to Java Applications. 2005 Pearson Education, Inc. All rights reserved.

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

CS 141: Introduction to (Java) Programming: Exam 1 Jenny Orr Willamette University Fall 2013

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

6.087 Lecture 2 January 12, 2010

6.087 Lecture 2 January 12, 2010 6.087 Lecture 2 January 12, 2010 Review Variables and data types Operators Epilogue 1 Review: C Programming language C is a fast, small,general-purpose,platform independent programming language. C is used

More information

Boolean Expressions, Conditions, Loops, and Enumerations. Precedence Rules (from highest to lowest priority)

Boolean Expressions, Conditions, Loops, and Enumerations. Precedence Rules (from highest to lowest priority) Boolean Expressions, Conditions, Loops, and Enumerations Relational Operators == // true if two values are equivalent!= // true if two values are not equivalent < // true if left value is less than the

More information

So far we have considered only numeric processing, i.e. processing of numeric data represented

So far we have considered only numeric processing, i.e. processing of numeric data represented Chapter 4 Processing Character Data So far we have considered only numeric processing, i.e. processing of numeric data represented as integer and oating point types. Humans also use computers to manipulate

More information

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

Introduction to Python

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

C PROGRAMMING FOR MATHEMATICAL COMPUTING

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

Example of a Java program

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

What is a Loop? Pretest Loops in C++ Types of Loop Testing. Count-controlled loops. Loops can be...

What is a Loop? Pretest Loops in C++ Types of Loop Testing. Count-controlled loops. Loops can be... What is a Loop? CSC Intermediate Programming Looping A loop is a repetition control structure It causes a single statement or a group of statements to be executed repeatedly It uses a condition to control

More information

Lecture 11 Doubly Linked Lists & Array of Linked Lists. Doubly Linked Lists

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

Goals. Unary Numbers. Decimal Numbers. 3,148 is. 1000 s 100 s 10 s 1 s. Number Bases 1/12/2009. COMP370 Intro to Computer Architecture 1

Goals. Unary Numbers. Decimal Numbers. 3,148 is. 1000 s 100 s 10 s 1 s. Number Bases 1/12/2009. COMP370 Intro to Computer Architecture 1 Number Bases //9 Goals Numbers Understand binary and hexadecimal numbers Be able to convert between number bases Understand binary fractions COMP37 Introduction to Computer Architecture Unary Numbers Decimal

More information

Scoping (Readings 7.1,7.4,7.6) Parameter passing methods (7.5) Building symbol tables (7.6)

Scoping (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 information

Java Interview Questions and Answers

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

JavaScript: Control Statements I

JavaScript: Control Statements I 1 7 JavaScript: Control Statements I 7.1 Introduction 2 The techniques you will learn here are applicable to most high-level languages, including JavaScript 1 7.2 Algorithms 3 Any computable problem can

More information

We will learn the Python programming language. Why? Because it is easy to learn and many people write programs in Python so we can share.

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

J a v a Quiz (Unit 3, Test 0 Practice)

J a v a Quiz (Unit 3, Test 0 Practice) Computer Science S-111a: Intensive Introduction to Computer Science Using Java Handout #11 Your Name Teaching Fellow J a v a Quiz (Unit 3, Test 0 Practice) Multiple-choice questions are worth 2 points

More information

The programming language C. sws1 1

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

PROGRAMMING IN C PROGRAMMING IN C CONTENT AT A GLANCE

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

Passing 1D arrays to functions.

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

C++FA 5.1 PRACTICE MID-TERM EXAM

C++FA 5.1 PRACTICE MID-TERM EXAM C++FA 5.1 PRACTICE MID-TERM EXAM This practicemid-term exam covers sections C++FA 1.1 through C++FA 1.4 of C++ with Financial Applications by Ben Van Vliet, available at www.benvanvliet.net. 1.) A pointer

More information

PL / SQL Basics. Chapter 3

PL / 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 information

Module 816. File Management in C. M. Campbell 1993 Deakin University

Module 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

Memory management. Announcements. Safe user input. Function pointers. Uses of function pointers. Function pointer example

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

Objective-C Tutorial

Objective-C Tutorial Objective-C Tutorial OBJECTIVE-C TUTORIAL Simply Easy Learning by tutorialspoint.com tutorialspoint.com i ABOUT THE TUTORIAL Objective-c tutorial Objective-C is a general-purpose, object-oriented programming

More information

Lecture 3. Arrays. Name of array. c[0] c[1] c[2] c[3] c[4] c[5] c[6] c[7] c[8] c[9] c[10] c[11] Position number of the element within array c

Lecture 3. Arrays. Name of array. c[0] c[1] c[2] c[3] c[4] c[5] c[6] c[7] c[8] c[9] c[10] c[11] Position number of the element within array c Lecture 3 Data structures arrays structs C strings: array of chars Arrays as parameters to functions Multiple subscripted arrays Structs as parameters to functions Default arguments Inline functions Redirection

More information

PART-A Questions. 2. How does an enumerated statement differ from a typedef statement?

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

Scanner. It takes input and splits it into a sequence of tokens. A token is a group of characters which form some unit.

Scanner. It takes input and splits it into a sequence of tokens. A token is a group of characters which form some unit. Scanner The Scanner class is intended to be used for input. It takes input and splits it into a sequence of tokens. A token is a group of characters which form some unit. For example, suppose the input

More information

Tutorial on C Language Programming

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

C++ Programming Language

C++ 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 information

Pemrograman Dasar. Basic Elements Of Java

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

In this Chapter you ll learn:

In this Chapter you ll learn: Now go, write it before them in a table, and note it in a book. Isaiah 30:8 To go beyond is as wrong as to fall short. Confucius Begin at the beginning, and go on till you come to the end: then stop. Lewis

More information

Introduction to Java. CS 3: Computer Programming in Java

Introduction to Java. CS 3: Computer Programming in Java Introduction to Java CS 3: Computer Programming in Java Objectives Begin with primitive data types Create a main class with helper methods Learn how to call built-in class methods and instance methods

More information

Topics. Parts of a Java Program. Topics (2) CS 146. Introduction To Computers And Java Chapter Objectives To understand:

Topics. Parts of a Java Program. Topics (2) CS 146. Introduction To Computers And Java Chapter Objectives To understand: Introduction to Programming and Algorithms Module 2 CS 146 Sam Houston State University Dr. Tim McGuire Introduction To Computers And Java Chapter Objectives To understand: the meaning and placement of

More information

Numbering Systems. InThisAppendix...

Numbering Systems. InThisAppendix... G InThisAppendix... Introduction Binary Numbering System Hexadecimal Numbering System Octal Numbering System Binary Coded Decimal (BCD) Numbering System Real (Floating Point) Numbering System BCD/Binary/Decimal/Hex/Octal

More information

Translating to Java. Translation. Input. Many Level Translations. read, get, input, ask, request. Requirements Design Algorithm Java Machine Language

Translating to Java. Translation. Input. Many Level Translations. read, get, input, ask, request. Requirements Design Algorithm Java Machine Language Translation Translating to Java Introduction to Computer Programming The job of a programmer is to translate a problem description into a computer language. You need to be able to convert a problem description

More information

Chapter One Introduction to Programming

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

C / C++ and Unix Programming. Materials adapted from Dan Hood and Dianna Xu

C / C++ and Unix Programming. Materials adapted from Dan Hood and Dianna Xu C / C++ and Unix Programming Materials adapted from Dan Hood and Dianna Xu 1 C and Unix Programming Today s goals ú History of C ú Basic types ú printf ú Arithmetic operations, types and casting ú Intro

More information

IC4 Programmer s Manual

IC4 Programmer s Manual IC4 Programmer s Manual Charles Winton 2002 KISS Institute for Practical Robotics www.kipr.org This manual may be distributed and used at no cost as long as it is not modified. Corrections to the manual

More information

AP Computer Science Java Subset

AP Computer Science Java Subset APPENDIX A AP Computer Science Java Subset The AP Java subset is intended to outline the features of Java that may appear on the AP Computer Science A Exam. The AP Java subset is NOT intended as an overall

More information

Chapter 13 Storage classes

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

Arrays. number: Motivation. Prof. Stewart Weiss. Software Design Lecture Notes Arrays

Arrays. number: Motivation. Prof. Stewart Weiss. Software Design Lecture Notes Arrays Motivation Suppose that we want a program that can read in a list of numbers and sort that list, or nd the largest value in that list. To be concrete about it, suppose we have 15 numbers to read in from

More information

PROBLEM SOLVING SEVENTH EDITION WALTER SAVITCH UNIVERSITY OF CALIFORNIA, SAN DIEGO CONTRIBUTOR KENRICK MOCK UNIVERSITY OF ALASKA, ANCHORAGE PEARSON

PROBLEM SOLVING SEVENTH EDITION WALTER SAVITCH UNIVERSITY OF CALIFORNIA, SAN DIEGO CONTRIBUTOR KENRICK MOCK UNIVERSITY OF ALASKA, ANCHORAGE PEARSON PROBLEM SOLVING WITH SEVENTH EDITION WALTER SAVITCH UNIVERSITY OF CALIFORNIA, SAN DIEGO CONTRIBUTOR KENRICK MOCK UNIVERSITY OF ALASKA, ANCHORAGE PEARSON Addison Wesley Boston San Francisco New York London

More information

1 Abstract Data Types Information Hiding

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

Chapter 3 Operators and Control Flow

Chapter 3 Operators and Control Flow Chapter 3 Operators and Control Flow I n this chapter, you will learn about operators, control flow statements, and the C# preprocessor. Operators provide syntax for performing different calculations or

More information

The University of Alabama in Huntsville Electrical and Computer Engineering CPE 112 01 Test #4 November 20, 2002. True or False (2 points each)

The University of Alabama in Huntsville Electrical and Computer Engineering CPE 112 01 Test #4 November 20, 2002. True or False (2 points each) True or False (2 points each) The University of Alabama in Huntsville Electrical and Computer Engineering CPE 112 01 Test #4 November 20, 2002 1. Using global variables is better style than using local

More information

JAVA - QUICK GUIDE. Java SE is freely available from the link Download Java. So you download a version based on your operating system.

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

DNA Data and Program Representation. Alexandre David 1.2.05 adavid@cs.aau.dk

DNA Data and Program Representation. Alexandre David 1.2.05 adavid@cs.aau.dk DNA Data and Program Representation Alexandre David 1.2.05 adavid@cs.aau.dk Introduction Very important to understand how data is represented. operations limits precision Digital logic built on 2-valued

More information

Computer Programming Tutorial

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

C++ Language Tutorial

C++ Language Tutorial cplusplus.com C++ Language Tutorial Written by: Juan Soulié Last revision: June, 2007 Available online at: http://www.cplusplus.com/doc/tutorial/ The online version is constantly revised and may contain

More information

VB.NET Programming Fundamentals

VB.NET Programming Fundamentals Chapter 3 Objectives Programming Fundamentals In this chapter, you will: Learn about the programming language Write a module definition Use variables and data types Compute with Write decision-making statements

More information

Computer Science Questions and Answers UNIT-A Chapter - 1 Configuring a Computer

Computer Science Questions and Answers UNIT-A Chapter - 1 Configuring a Computer I One Mark Question and Answer 1. Name the components of CPU Computer Science Questions and Answers UNIT-A Chapter - 1 Configuring a Computer Ans. a) ALU b) PC c) Accumulator d) MAR e) IR f) ID g) MDR

More information

Handout 1. Introduction to Java programming language. Java primitive types and operations. Reading keyboard Input using class Scanner.

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

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

Storage Classes CS 110B - Rule Storage Classes Page 18-1 \handouts\storclas

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

CS1020 Data Structures and Algorithms I Lecture Note #1. Introduction to Java

CS1020 Data Structures and Algorithms I Lecture Note #1. Introduction to Java CS1020 Data Structures and Algorithms I Lecture Note #1 Introduction to Java Objectives Java Basic Java features C Java Translate C programs in CS1010 into Java programs 2 References Chapter 1 Section

More information

Chapter 2 Elementary Programming

Chapter 2 Elementary Programming Chapter 2 Elementary Programming 2.1 Introduction You will learn elementary programming using Java primitive data types and related subjects, such as variables, constants, operators, expressions, and input

More information

Semantic Analysis: Types and Type Checking

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

Statements and Control Flow

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

COMP 250 Fall 2012 lecture 2 binary representations Sept. 11, 2012

COMP 250 Fall 2012 lecture 2 binary representations Sept. 11, 2012 Binary numbers The reason humans represent numbers using decimal (the ten digits from 0,1,... 9) is that we have ten fingers. There is no other reason than that. There is nothing special otherwise about

More information

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

Embedded Programming in C/C++: Lesson-1: Programming Elements and Programming in C

Embedded Programming in C/C++: Lesson-1: Programming Elements and Programming in C Embedded Programming in C/C++: Lesson-1: Programming Elements and Programming in C 1 An essential part of any embedded system design Programming 2 Programming in Assembly or HLL Processor and memory-sensitive

More information

3/13/2012. Writing Simple C Programs. ESc101: Decision making using if-else and switch statements. Writing Simple C Programs

3/13/2012. Writing Simple C Programs. ESc101: Decision making using if-else and switch statements. Writing Simple C Programs Writing Simple C Programs ESc101: Decision making using if- and switch statements Instructor: Krithika Venkataramani Semester 2, 2011-2012 Use standard files having predefined instructions stdio.h: has

More information

System Calls and Standard I/O

System Calls and Standard I/O System Calls and Standard I/O Professor Jennifer Rexford http://www.cs.princeton.edu/~jrex 1 Goals of Today s Class System calls o How a user process contacts the Operating System o For advanced services

More information

The Payroll Program. Payroll

The Payroll Program. Payroll The Program 1 The following example is a simple payroll program that illustrates most of the core elements of the C++ language covered in sections 3 through 6 of the course notes. During the term, a formal

More information

Number Representation

Number Representation Number Representation CS10001: Programming & Data Structures Pallab Dasgupta Professor, Dept. of Computer Sc. & Engg., Indian Institute of Technology Kharagpur Topics to be Discussed How are numeric data

More information

Introduction to Programming (in C++) Loops. Jordi Cortadella, Ricard Gavaldà, Fernando Orejas Dept. of Computer Science, UPC

Introduction to Programming (in C++) Loops. Jordi Cortadella, Ricard Gavaldà, Fernando Orejas Dept. of Computer Science, UPC Introduction to Programming (in C++) Loops Jordi Cortadella, Ricard Gavaldà, Fernando Orejas Dept. of Computer Science, UPC Example Assume the following specification: Input: read a number N > 0 Output:

More information

Example. Introduction to Programming (in C++) Loops. The while statement. Write the numbers 1 N. Assume the following specification:

Example. Introduction to Programming (in C++) Loops. The while statement. Write the numbers 1 N. Assume the following specification: Example Introduction to Programming (in C++) Loops Assume the following specification: Input: read a number N > 0 Output: write the sequence 1 2 3 N (one number per line) Jordi Cortadella, Ricard Gavaldà,

More information

CS 241 Data Organization Coding Standards

CS 241 Data Organization Coding Standards CS 241 Data Organization Coding Standards Brooke Chenoweth University of New Mexico Spring 2016 CS-241 Coding Standards All projects and labs must follow the great and hallowed CS-241 coding standards.

More information

Fundamentals of Programming

Fundamentals of Programming Fundamentals of Programming Introduction to the C language Giuseppe Lipari http://retis.sssup.it/~lipari Scuola Superiore Sant Anna Pisa February 29, 2012 G. Lipari (Scuola Superiore Sant Anna) The C language

More information

Parallel and Distributed Computing Programming Assignment 1

Parallel and Distributed Computing Programming Assignment 1 Parallel and Distributed Computing Programming Assignment 1 Due Monday, February 7 For programming assignment 1, you should write two C programs. One should provide an estimate of the performance of ping-pong

More information

An Introduction to Assembly Programming with the ARM 32-bit Processor Family

An Introduction to Assembly Programming with the ARM 32-bit Processor Family An Introduction to Assembly Programming with the ARM 32-bit Processor Family G. Agosta Politecnico di Milano December 3, 2011 Contents 1 Introduction 1 1.1 Prerequisites............................. 2

More information

Masters programmes in Computer Science and Information Systems. Object-Oriented Design and Programming. Sample module entry test xxth December 2013

Masters programmes in Computer Science and Information Systems. Object-Oriented Design and Programming. Sample module entry test xxth December 2013 Masters programmes in Computer Science and Information Systems Object-Oriented Design and Programming Sample module entry test xxth December 2013 This sample paper has more questions than the real paper

More information

C Programming. for Embedded Microcontrollers. Warwick A. Smith. Postbus 11. Elektor International Media BV. 6114ZG Susteren The Netherlands

C Programming. for Embedded Microcontrollers. Warwick A. Smith. Postbus 11. Elektor International Media BV. 6114ZG Susteren The Netherlands C Programming for Embedded Microcontrollers Warwick A. Smith Elektor International Media BV Postbus 11 6114ZG Susteren The Netherlands 3 the Table of Contents Introduction 11 Target Audience 11 What is

More information

El Dorado Union High School District Educational Services

El Dorado Union High School District Educational Services El Dorado Union High School District Course of Study Information Page Course Title: ACE Computer Programming II (#495) Rationale: A continuum of courses, including advanced classes in technology is needed.

More information

Moving from CS 61A Scheme to CS 61B Java

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

Phys4051: C Lecture 2 & 3. Comment Statements. C Data Types. Functions (Review) Comment Statements Variables & Operators Branching Instructions

Phys4051: C Lecture 2 & 3. Comment Statements. C Data Types. Functions (Review) Comment Statements Variables & Operators Branching Instructions Phys4051: C Lecture 2 & 3 Functions (Review) Comment Statements Variables & Operators Branching Instructions Comment Statements! Method 1: /* */! Method 2: // /* Single Line */ //Single Line /* This comment

More information

FEEG6002 - Applied Programming 5 - Tutorial Session

FEEG6002 - Applied Programming 5 - Tutorial Session FEEG6002 - Applied Programming 5 - Tutorial Session Sam Sinayoko 2015-10-30 1 / 38 Outline Objectives Two common bugs General comments on style String formatting Questions? Summary 2 / 38 Objectives Revise

More information

Bachelors of Computer Application Programming Principle & Algorithm (BCA-S102T)

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