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

Size: px
Start display at page:

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

Transcription

1 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 tokens: keywords : these are reserved identifiers having predefined meanings identifiers : these tokens name functions, variables, constants, and types literals : these tokens that specify values operators : these tokens are used to combine values in expressions punctuation : these tokens separate or terminate complex constructions 2. Explain C Keywords Keywords are identifiers having predefined meanings in C programming language. The list of keywords used in standard C are : auto double int struct break Else long switch case enum register typedef char extern return union const float short continue default for Goto signed sizeof volatile Do If static while unsigned void All 32 keywords are in lower case letters. These keywords are reserved and cannot be redefined. Following rules must be kept in mind when using keywords. Keywords are case sensitive. The keywords have special meaning in the language and cannot be used for any other purpose such as constant name or variable name. 3. State the use of %d and %f. Write a print statement in C using above mentioned symbols %d and %f are conversion specifiers. They are used with the control string in i n p u t f u n c t i o n s c a n f ( ) a n d o u t p u t f u n c t i o n p r i n t f ( ) Consider the following statement printf ( radius=%d, area= %f, r,a) ; The control-string uses %d conversion specifier. It describes how the value of n will be printed. The following example shows use of %d. In this example %d is used in scanf()

2 statement to accept an integer value. Again %d is used in the printf() statement to print the integer value. int a; printf ( Please enter an integer ); scanf( %d,&a) printf ( you entered the value %d,a); The next example shows use of %f. In this example %f is used in scanf() statement to accept a float value. Again %f is used in the printf() statement to print the float value. int b; printf ( Please enter a float number ); scanf( %f,&b) printf ( you entered the value %f,b); 4. Define expressions Expressions: Expression is a single value or a combination of values and variables which are connected by operators. Following are examples of expression: a + b - c ; x = a ; x > 6 ; The first expression uses arithmetic operators + and, the second expression uses the assignment operator =, and the third expression uses relational operator >. Expression can also be a logical condition that is or false. In C the and false condition are represented by integer value 1 and 0 respectively. 5. What are operators? Operators: Operators are tokens used to combine values in an expression. The following are examples of operators used in an expression: a + b - c ;

3 x = a ; x > 6 ; The first expression uses arithmetic operators + and, the second expression uses the assignment operator =, and the third expression uses relational operator >. Some operators perform operation on two operands, while others perform operation on only one operand. Explain the various operators used in C Explain the bit wise operators in C Explain the logical operators used in C What is an operator? Explain unary and binary operators. Explain the increment and decrement operators. State four arithmetic operators and four logical operators of C The operators used in C are divided into following types: Arithmetic Operators Relation Operator Logical Operator Arithmetic Operators: The operators used for basic arithmetic are =, +, -, *, and /. Operator Meaning subtraction + addition * multiplication / division % modulus The operator % is used in integer arithmetic. It is called modulus operator. It gives the remainder when the integer to its left is divided by the integer to its right. Example: 13 % 5 is read as "13 modulo 5" and it has the value 3 The modulus operation gives remainder of an integer division. Hence % cannot be used in type float or double. Unary Operators: These operators perform an operation on a single variable and give a new value. The unary operators are: Operator Meaning Unary negative + Unary positive ++ Unary increment Unary decrement sizeof size of variable in

4 A B Unary Minus: This operator is used to negate a numerical constant, variable or a expression. Examples: (a * b) a + 35 Increment operator: The operator ++ will increase the value of its operand by 1.. Decrement operator: The operator will decrease the value of its operand by 1. Sizeof operator: This operator will return the size of the operand. The operand can be an expression. Example: int p=10; float q = 2.5 ; printf ( the size of p in byte is %d, sizeof(p)); printf ( the size of q in byte is %d, sizeof(q)); The output of this will be the size of p in byte is 2 the size of q in byte is 4 Bitwise Boolean Operators: The six bit wise operators used in C are given below. The bit wise operators work bit by bit on operands. The operands must be of integral type. & AND OR ^ XOR (exclusive OR) ~ NOT ( changes 1 to 0 and 0 to << 1) Shift left >> Shift right Logical Operators: The logical operators used in C are given below. && logical if any one operand is false, the result is false logical OR if any one operand is, the result is! NOT if the operand is, the result is false and vice versa

5 false false false false The operators && and are binary operators i.e. the logical operators require two operands. The! operator is a unary operator. false Consider operands A and B. The truth table for && and operators are given below A B A && B false false false false false false false These logical operators are used to combine or negate expression containing relational operators. Here's an example of a logical expression. r = ((a&&b) (c>d)); In the example: r is set equal to 1 if a and b are nonzero, or if c is greater than d. In all other cases, r is set to 0. Define/Explain Data Types Every variables used in a C program is defined with a specific type. In Standard C there are four basic data types. They are int, char, float, and double. char - characters int - integers (whole numbers) float - real numbers double - higher precision real numbers In addition, C provides structured types: array - groups of variables of identical types, accessed using integer indices structs - groups of variables of mixed types, accessed by using named field selectors unions - variables that can contain values of different types, depending on a field selector C also allows enumerated types - variables that can take on a small number of different named values Explain the break statement The break statement is used in loop statements (for, while, and do-while). It is possible to force an immediate exit from a loop by using the break statement. A break statement is formed with the keyword break followed by a semicolon.

6 Example : #include <stdio.h> int x; for(x=1;x<=100;x++) if(x==10) printf( %d, x); printf ( loop terminated ); When the break statement is encountered inside a loop, the loop is immediately terminated and program control resumes at the next statement following the loop. Break is also used in switch statements to terminate execution of statement. When the break statement is executed, execution proceeds to the statement that follows switch statement. Example : int n; printf( \nenter a number between 1 to 3 ); scanf( %d,%n); switch (n) case 1 : printf( you entered 1 ); case 2 : printf( you entered 2 ); case 3 : printf( you entered 3 ); default : printf( wrong choice ); Explain the continue statement It is possible to bypass the loops normal control structure and force an early iteration of a loop and. This is accomplished by using continue. The continue statement is used in loop statements (for, while, and do-while) to terminate iteration of the loop. The next iteration of loop to takes place, skipping code between itself and conditional expression that controls

7 the loop. A continue statement is formed with the keyword continue followed by a semicolon. Example: The following program prints even numbers between 0 and 100 #include <stdio.h> int x; for(x=0;x<=100;x++) if(x%2!=0) continue; printf( %d,x); After a continue statement is executed, execution proceeds to increment clause and continuation test of for loop. Hence only even numbers are printed because an odd one will cause the loop to iterate early. The continue statement can be used in while and do while loops. It will cause control to go directly to the conditional expression and then continue the looping process. The continue statement is useful when data in body of loop is bad, out of bounds or unexpected. Instead of acting on bad data, control can go back to top of loop and get another data value. Give the selection process of the switch statement Explain switch case statement with syntax The switch statement is used to select and execute a particular group of statement from several available groups. The selection is based on the value of an expression or variable The syntax of the switch statement is: switch (expression or variable) case constant1 : statement-block1; case constant2 : statement-block2;... case constantn : statement-blockn; case default : statement-block3; where expression is of simple type such as int, char, or enum. It cannot have float or double type.

8 When switch statement is executed, the expression is evaluated. The resulting value is compared to values of constants 1 through N in order until a matching value is found. If a match is found in constant i then statements-block i through N and the default statements will be executed. Normally, last statement in each statement-block is a break statement so that only one statement-block is executed. The default clause is optional. If it is present then the default-statements are executed whenever value of expression does not match the constant values. Example: The program defines variable v of char type. The program takes input and stores it in variable v. The program will check the value of v and match it with the several cases. If the case matches the corresponding statement is executed. char v; printf( \nenter a vowel : ); scanf( %d,%c); switch (v) case a : printf( you entered a ); case e : printf( you entered e ); case i : printf( you entered i ); case o : printf( you entered o ); case u : printf( you entered u ); default : printf( you did not enter a vowel ) Example : In this example, the switch statement will allows execution of different statements depending on the value of n entered by the user. int n; printf( \nenter a number between 1 to 3 ); scanf( %d,%n); switch (n) case 1 : printf( you entered 1 );

9 case 2 : printf( you entered 2 ); case 3 : printf( you entered 3 ); default : printf( wrong choice ) Explain the for-statement. Give the syntax of for-statement The for statement is a looping construction. It has the following form: for (initialization; condition; increment) statements where initialization is a statement that is executed once at beginning of for loop. condition is an expression that can be (nonzero) or false (zero). This expression is tested prior to each iteration of the loop. The loop terminates when it is false. increment is a statement that is executed after statements. statements is a sequence of statements. If there is only one statement then the braces may be omitted. Example: The following program will print the numbers 1 to 10 in reverse order int i ; for (i=10 ; i>=0 ; i--) printf( %d\n,i); Example: The following program will print the sum of numbers from 1 to 10 int i,sum = 0 ; for (i=1 ; i<=10 ; i++) sum=sum + i ; printf( sum = %d,sum); Example: The following program will print the sum of all even numbers from 1 to 100

10 int i,sum = 0 ; for (i=2 ; i<=100 ; i=i+2) sum=sum + i ; printf( sum of even numbers = %d,sum); Example: The following program will print the first 10 odd numbers int i ; for (i=1 ; i<=20 ; i=i+2) printf( %d\n,i); Explain the syntax of while statement The while statement is a looping construction which has the following form: while (loop condition) statement block; where: loop condition is an expression that can be (nonzero) or false (zero). This expression is tested prior to each iteration of the loop. The loop terminates when it is false. When the condition is false, control will go to the first statement after the curly bracket statements is a sequence of statements. If there is only one statement then the braces can be omitted. Example: The following program will print the first 10 natural numbers. The loop is executed 10 times. int i=1 ; while (i<=10) printf( %d\n,i); i++; Explain : Do-While Loops

11 The do-while statement is a looping construction. It has following form:

12 do statement block ; while (loop condition); where statements is a sequence of statements. If there is only one statement then the braces may be omitted. condition is an expression that can be (nonzero) or false (zero). This expression is tested after each iteration of the loop. The loop terminates when it is false. Example: The following program will print the first 10 natural numbers. The loop is executed 10 times. int i=1 ; do printf( %d\n,i); i++; while (i<=10) Give the syntax of the simple if- statement The simplest form of if statement is as follows: if (condition) statement; The if keyword must be followed by a set of parentheses containing the expression to be tested. The parentheses is followed by a single statement which is executed only if the test expression evaluates to. Example: The following program uses the simple if statement: int n; printf( Enter a positive number less than 10 ); scanf( %d,&n); if (n<=10) printf("thank you ); if (n>10) printf("sorry. The number is greater than 10 );

13 Describe the if- statement

14 The if statement has one of two forms: if (condition) -statements or if (condition) -statements false-statements where condition is an expression that can be (nonzero) or false (zero). -statements and false-statements are sequences of statements. If there is only one statement in a sequence then the surrounding braces may be omitted. The second form includes the clause For both forms, -statements are executed only if condition is. For second form the false-statements are executed if condition is false. Example : The following statement is used to test whether a number entered by the user is positive or negative #include <stdio.h> void main () int n ; printf ("Enter a non-zero number") ; scanf ("%d", &n); if (n < 0) printf ("number is negative") ; printf ("The number is positive") ; Example: Finding the greater of two numbers #include <stdio.h> void main () int a,b ;

15 printf ("Enter a number") ; scanf ("%d", &a); printf ("Enter another number") ; scanf ("%d", &b); if (a>b) printf ("%d is greater than %d", a,b) ; printf ("%d is greater than %d", a,b) ; State two types of if statement The simplest form of if statement is as follows: If one statement at this point, there is no need to use curly braces. if (condition) statement; If m o re than one statement, they may be grouped using curly braces. Such statement group is called compound statement. if (condition) Statement1; Statement2; The general form of the if statement includes the clause is as follows. if (condition) statement; statement; if (condition) statement; statement; Statement; statement; Example: The following example uses if statement to find the greatest of three numbers entered by the user. #include <stdio.h> main () int a, b, c, big ; printf ("Enter three numbers"); scanf ("%d %d %d", &a, &b, &c);

16 if (a > b) && (a > c) big = a ; if (b > c) big = b ; big = c ; printf ("largest number is %d", big) Explain the nesting of if-statement The if statement can itself contain another if statement. This is known as nesting of if statement. The nested if may appear in a program as : if(condition 1) if(condition 2) statement 1; statement 2; if(condition 3) statement 3; statement 4; The main thing to remember about nested if is that the statement always refers to the nearest if statement within the same block. Example : This program uses the nested if to find greatest of three numbers #include <stdio.h> main () int a, b, c, big ; printf ("Enter three numbers"); scanf ("%d %d %d", &a, &b, &c); if (a > b) if (a > c) big = a ;

17 big = c; if (b > c) big = b ; big = c ; printf ("largest of %d, %d & %d = %d", a, b, c, big) ; Explain the -if ladder with example The construct of -if ladder is shown below : if(condition1) statement1 ; if(condition1) statement1 ; if(condition2) statement2 ;... if(conditionn) statementn ; statement ; The conditional expressions are evaluated from top downward. When a condition is found, the associated statement is executed, and rest of ladder is bypassed. If none of conditions is, then final statement is executed. The final acts as a default condition i.e. if all other conditions tests fail, then the last statement is performed. If there is no final and all other conditions are false then no action will take place. Example : Following example illustrates the of if--if ladder #include <stdio.h> main () int n; printf("enter an integer between 1 and 5"); scanf( %d,n);

18 if(n==1) printf("number is one\n"); if(n==2) printf("number is two\n"); if(n==3) printf("number is three\n"); if(n==4) printf("number is four\n"); if(n==5) printf("number is five\n"); printf("you didn't follow the rules"); Explain the? : operator (Conditional Operator) C language uses a combination of? and : for making two way decisions. This operator is called the conditional operator and it takes three operands. The general form of the conditional operator is : conditional expression? expression1 : expression2 The conditional expression is first evaluated. If result is non-zero, then expression1 is evaluated and its value is returned. If result is zero, then expression2 is evaluated and its value is returned. Example : Consider the following code : if (x>3) a = 5; a = 1; The same can be written as : a = (x>3)? 5 : 1 ; The conditional operator can be nested for more complex assignments. For example consider the following Salary = 4R+20 for R < 20 = 150 for R = 20 = 5R+90 for R > 20 This can be written as: salary = (R=20)? 150:((R<20)? (4*R+20):(5*R+90)) The code is concise, but more difficult to read. Hence it is better to use if statements when nesting of conditional operator is required. if (R=20) salary = 150 ; if R < 20 salary = 4*R+20 ; salary = 5*R+90 ;

19

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

Lecture 2 Notes: Flow of Control

Lecture 2 Notes: Flow of Control 6.096 Introduction to C++ January, 2011 Massachusetts Institute of Technology John Marrero Lecture 2 Notes: Flow of Control 1 Motivation Normally, a program executes statements from first to last. The

More information

6. Control Structures

6. Control Structures - 35 - Control Structures: 6. Control Structures A program is usually not limited to a linear sequence of instructions. During its process it may bifurcate, repeat code or take decisions. For that purpose,

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

9 Control Statements. 9.1 Introduction. 9.2 Objectives. 9.3 Statements

9 Control Statements. 9.1 Introduction. 9.2 Objectives. 9.3 Statements 9 Control Statements 9.1 Introduction The normal flow of execution in a high level language is sequential, i.e., each statement is executed in the order of its appearance in the program. However, depending

More information

Object Oriented Software Design

Object Oriented Software Design Object Oriented Software Design Introduction to Java - II Giuseppe Lipari http://retis.sssup.it/~lipari Scuola Superiore Sant Anna Pisa September 14, 2011 G. Lipari (Scuola Superiore Sant Anna) Introduction

More 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

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

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

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

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

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

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

UIL Computer Science for Dummies by Jake Warren and works from Mr. Fleming

UIL Computer Science for Dummies by Jake Warren and works from Mr. Fleming UIL Computer Science for Dummies by Jake Warren and works from Mr. Fleming 1 2 Foreword First of all, this book isn t really for dummies. I wrote it for myself and other kids who are on the team. Everything

More 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

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

Two-way selection. Branching and Looping

Two-way selection. Branching and Looping Control Structures: are those statements that decide the order in which individual statements or instructions of a program are executed or evaluated. Control Structures are broadly classified into: 1.

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

Object Oriented Software Design

Object Oriented Software Design Object Oriented Software Design Introduction to Java - II Giuseppe Lipari http://retis.sssup.it/~lipari Scuola Superiore Sant Anna Pisa October 28, 2010 G. Lipari (Scuola Superiore Sant Anna) Introduction

More information

Selection Statements

Selection Statements Chapter 5 Selection Statements 1 Statements So far, we ve used return statements and expression ess statements. e ts. Most of C s remaining statements fall into three categories: Selection statements:

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

Outline. Conditional Statements. Logical Data in C. Logical Expressions. Relational Examples. Relational Operators

Outline. Conditional Statements. Logical Data in C. Logical Expressions. Relational Examples. Relational Operators Conditional Statements For computer to make decisions, must be able to test CONDITIONS IF it is raining THEN I will not go outside IF Count is not zero THEN the Average is Sum divided by Count Conditions

More 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

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

C Programming Tutorial

C Programming Tutorial C Programming Tutorial C PROGRAMMING TUTORIAL Simply Easy Learning by tutorialspoint.com tutorialspoint.com i C O P Y R I G H T & D I S C L A I M E R N O T I C E All the content and graphics on this tutorial

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

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

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

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

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

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

Conditions & Boolean Expressions

Conditions & Boolean Expressions Conditions & Boolean Expressions 1 In C++, in order to ask a question, a program makes an assertion which is evaluated to either true (nonzero) or false (zero) by the computer at run time. Example: In

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

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

13 Classes & Objects with Constructors/Destructors

13 Classes & Objects with Constructors/Destructors 13 Classes & Objects with Constructors/Destructors 13.1 Introduction In object oriented programming, the emphasis is on data rather than function. Class is a way that binds the data & function together.

More 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

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

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

TIP: To access the WinRunner help system at any time, press the F1 key.

TIP: To access the WinRunner help system at any time, press the F1 key. CHAPTER 11 TEST SCRIPT LANGUAGE We will now look at the TSL language. You have already been exposed to this language at various points of this book. All the recorded scripts that WinRunner creates when

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

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

C++ INTERVIEW QUESTIONS

C++ INTERVIEW QUESTIONS C++ INTERVIEW QUESTIONS http://www.tutorialspoint.com/cplusplus/cpp_interview_questions.htm Copyright tutorialspoint.com Dear readers, these C++ Interview Questions have been designed specially to get

More 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

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

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

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

MISRA-C:2012 Standards Model Summary for C / C++ MISRA-C:2012 Standards Model Summary for C / C++ The LDRA tool suite is developed and certified to BS EN ISO 9001:2000. This information is applicable to version 9.4.2 of the LDRA tool suite. It is correct

More 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

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

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

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

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

While Loop. 6. Iteration

While Loop. 6. Iteration While Loop 1 Loop - a control structure that causes a set of statements to be executed repeatedly, (reiterated). While statement - most versatile type of loop in C++ false while boolean expression true

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

Chapter 8 Selection 8-1

Chapter 8 Selection 8-1 Chapter 8 Selection 8-1 Selection (Decision) The second control logic structure is selection: Selection Choosing between two or more alternative actions. Selection statements alter the sequential flow

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

Boolean Data Outline

Boolean Data Outline 1. Boolean Data Outline 2. Data Types 3. C Boolean Data Type: char or int 4. C Built-In Boolean Data Type: bool 5. bool Data Type: Not Used in CS1313 6. Boolean Declaration 7. Boolean or Character? 8.

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

1.00/1.001 - Session 2 Fall 2004. Basic Java Data Types, Control Structures. Java Data Types. 8 primitive or built-in data types

1.00/1.001 - Session 2 Fall 2004. Basic Java Data Types, Control Structures. Java Data Types. 8 primitive or built-in data types 1.00/1.001 - Session 2 Fall 2004 Basic Java Data Types, Control Structures Java Data Types 8 primitive or built-in data types 4 integer types (byte, short, int, long) 2 floating point types (float, double)

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

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

I PUC - Computer Science. Practical s Syllabus. Contents

I PUC - Computer Science. Practical s Syllabus. Contents I PUC - Computer Science Practical s Syllabus Contents Topics 1 Overview Of a Computer 1.1 Introduction 1.2 Functional Components of a computer (Working of each unit) 1.3 Evolution Of Computers 1.4 Generations

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

4.8 Thedo while Repetition Statement Thedo while repetition statement

4.8 Thedo while Repetition Statement Thedo while repetition statement 1 4.8 hedo while Repetition Statement hedo while repetition statement Similar to thewhile structure Condition for repetition tested after the body of the loop is performed All actions are performed at

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

The C++ Language. Loops. ! Recall that a loop is another of the four basic programming language structures

The C++ Language. Loops. ! Recall that a loop is another of the four basic programming language structures The C++ Language Loops Loops! Recall that a loop is another of the four basic programming language structures Repeat statements until some condition is false. Condition False True Statement1 2 1 Loops

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

Why using ATmega16? University of Wollongong Australia. 7.1 Overview of ATmega16. Overview of ATmega16

Why using ATmega16? University of Wollongong Australia. 7.1 Overview of ATmega16. Overview of ATmega16 s schedule Lecture 7 - C Programming for the Atmel AVR School of Electrical, l Computer and Telecommunications i Engineering i University of Wollongong Australia Week Lecture (2h) Tutorial (1h) Lab (2h)

More information

Keil C51 Cross Compiler

Keil C51 Cross Compiler Keil C51 Cross Compiler ANSI C Compiler Generates fast compact code for the 8051 and it s derivatives Advantages of C over Assembler Do not need to know the microcontroller instruction set Register allocation

More 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

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

Lecture 1 Introduction to Java

Lecture 1 Introduction to Java Programming Languages: Java Lecture 1 Introduction to Java Instructor: Omer Boyaci 1 2 Course Information History of Java Introduction First Program in Java: Printing a Line of Text Modifying Our First

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 if Statement and Practice Problems

The if Statement and Practice Problems The if Statement and Practice Problems The Simple if Statement Use To specify the conditions under which a statement or group of statements should be executed. Form if (boolean-expression) statement; where

More information

Common Beginner C++ Programming Mistakes

Common Beginner C++ Programming Mistakes Common Beginner C++ Programming Mistakes This documents some common C++ mistakes that beginning programmers make. These errors are two types: Syntax errors these are detected at compile time and you won't

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

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

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

Writing Control Structures

Writing Control Structures Writing Control Structures Copyright 2006, Oracle. All rights reserved. Oracle Database 10g: PL/SQL Fundamentals 5-1 Objectives After completing this lesson, you should be able to do the following: Identify

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

Numeral Systems. The number twenty-five can be represented in many ways: Decimal system (base 10): 25 Roman numerals:

Numeral Systems. The number twenty-five can be represented in many ways: Decimal system (base 10): 25 Roman numerals: Numeral Systems Which number is larger? 25 8 We need to distinguish between numbers and the symbols that represent them, called numerals. The number 25 is larger than 8, but the numeral 8 above is larger

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

Moving from C++ to VBA

Moving from C++ to VBA Introduction College of Engineering and Computer Science Mechanical Engineering Department Mechanical Engineering 309 Numerical Analysis of Engineering Systems Fall 2014 Number: 15237 Instructor: Larry

More information

A single register, called the accumulator, stores the. operand before the operation, and stores the result. Add y # add y from memory to the acc

A single register, called the accumulator, stores the. operand before the operation, and stores the result. Add y # add y from memory to the acc Other architectures Example. Accumulator-based machines A single register, called the accumulator, stores the operand before the operation, and stores the result after the operation. Load x # into acc

More information

C++ program structure Variable Declarations

C++ program structure Variable Declarations C++ program structure A C++ program consists of Declarations of global types, variables, and functions. The scope of globally defined types, variables, and functions is limited to the file in which they

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

C++ Essentials. Sharam Hekmat PragSoft Corporation www.pragsoft.com

C++ Essentials. Sharam Hekmat PragSoft Corporation www.pragsoft.com C++ Essentials Sharam Hekmat PragSoft Corporation www.pragsoft.com Contents Contents Preface 1. Preliminaries 1 A Simple C++ Program 2 Compiling a Simple C++ Program 3 How C++ Compilation Works 4 Variables

More information

Conditional Statements. 15-110 Summer 2010 Margaret Reid-Miller

Conditional Statements. 15-110 Summer 2010 Margaret Reid-Miller Conditional Statements 15-110 Summer 2010 Margaret Reid-Miller Conditional statements Within a method, we can alter the flow of control (the order in which statements are executed) using either conditionals

More information

ESCI 386 IDL Programming for Advanced Earth Science Applications Lesson 6 Program Control

ESCI 386 IDL Programming for Advanced Earth Science Applications Lesson 6 Program Control ESCI 386 IDL Programming for Advanced Earth Science Applications Lesson 6 Program Control Reading: Bowman, Chapters 16 CODE BLOCKS A code block consists of several lines of code contained between a BEGIN

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

JavaScript: Introduction to Scripting. 2008 Pearson Education, Inc. All rights reserved.

JavaScript: Introduction to Scripting. 2008 Pearson Education, Inc. All rights reserved. 1 6 JavaScript: Introduction to Scripting 2 Comment is free, but facts are sacred. C. P. Scott The creditor hath a better memory than the debtor. James Howell When faced with a decision, I always ask,

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

Conditionals (with solutions)

Conditionals (with solutions) Conditionals (with solutions) For exercises 1 to 27, indicate the output that will be produced. Assume the following declarations: final int MAX = 25, LIMIT = 100; int num1 = 12, num2 = 25, num3 = 87;

More information

Answers to Review Questions Chapter 7

Answers to Review Questions Chapter 7 Answers to Review Questions Chapter 7 1. The size declarator is used in a definition of an array to indicate the number of elements the array will have. A subscript is used to access a specific element

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

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

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

1 Description of The Simpletron

1 Description of The Simpletron Simulating The Simpletron Computer 50 points 1 Description of The Simpletron In this assignment you will write a program to simulate a fictional computer that we will call the Simpletron. As its name implies

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