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

Punctuation in C. Identifiers and Expressions. Identifiers. Variables. Keywords. Identifier Examples

Punctuation in C. Identifiers and Expressions. Identifiers. Variables. Keywords. Identifier Examples Identifiers and Expressions CSE 130: Introduction to C Programming Spring 2005 Punctuation in C Statements are terminated with a ; Groups of statements are enclosed by curly braces: { and } Commas separate

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

14 MAKING DECISIONS IN C

14 MAKING DECISIONS IN C 14 MAKING DECISIONS IN C 14.1 INTRODUCTION So far we have seen that in C programs the instructions are executed in the same order in which they appear in the program. Each instruction is executed once

More information

C Programming Dr. Hasan Demirel

C Programming Dr. Hasan Demirel C How to Program, H. M. Deitel and P. J. Deitel, Prentice Hall, 5 th edition (3 rd edition or above is also OK). Introduction to C Programming Dr. Hasan Demirel Programming Languages There are three types

More information

GETTING STARTED WITH C++ C++ BASICS - 1 -

GETTING STARTED WITH C++ C++ BASICS - 1 - - 1 - GETTING STARTED WITH C++ Programming is a core activity in the process of performing tasks or solving problems with the aid of a computer. An idealised picture is: PROBLEM COMPUTER SOLUTION Unfortunately

More information

Java provides a rich set of operators to manipulate variables. We can divide all the Java operators into the following groups:

Java provides a rich set of operators to manipulate variables. We can divide all the Java operators into the following groups: JAVA OPERATORS GENERAL Java provides a rich set of operators to manipulate variables. We can divide all the Java operators into the following groups: Arithmetic Operators Relational Operators Bitwise Operators

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

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

Chapter 2: Problem Solving Using C++

Chapter 2: Problem Solving Using C++ Chapter 2: Problem Solving Using C++ 1 Objectives In this chapter, you will learn about: Modular programs Programming style Data types Arithmetic operations Variables and declaration statements Common

More information

Basic Common Unix commands: Change to directory d

Basic Common Unix commands: Change to directory d Basic Common Unix commands: cd d Change to directory d mkdir d rmdir d mv f1 [f2...] d mv d1 d2 ls [d] [f...] ls -1 [f...] vi [f] emacs [f] more f cp f1 f2 mv f1 f2 rm f gcc [-o f1] f2 gnuplot Create new

More information

1. Constants. 2. Variables. 3. Reserved words or key words. 4. Constants. Character set in C

1. Constants. 2. Variables. 3. Reserved words or key words. 4. Constants. Character set in C Character set in C We should use only the following characters in writing a C program. These characters can be combined to create C words. Alphabet: A, B, C, D.. Z, a, b, c, d..z Numeric digits: 0, 1,

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

C AND C++ PROGRAMMING

C AND C++ PROGRAMMING C AND C++ PROGRAMMING Bharathidasan University A Courseware prepared by University Informatics Centre Part I - Programming in C Getting Started This courseware is intended to be an introduction to C programming

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 Review (Essentials of Java for Hadoop)

Java Review (Essentials of Java for Hadoop) Java Review (Essentials of Java for Hadoop) Have You Joined Our LinkedIn Group? What is Java? Java JRE - Java is not just a programming language but it is a complete platform for object oriented programming.

More information

UNIT-1. C Programming & Data Structures. Introduction to Computers: Computing Environment: Types of Computing Environments:

UNIT-1. C Programming & Data Structures. Introduction to Computers: Computing Environment: Types of Computing Environments: Introduction to Computers: C Programming & Data Structures UNIT-1 A computer system consists of hardware and software. Computer hardware is the collection of physical elements that comprise a computer

More information

Chapter 8. Arithmetic in C++

Chapter 8. Arithmetic in C++ Christian Jacob Chapter 8 Arithmetic in C++ 8.1 The C++ Vocabulary 8.2 Variables and Types 8.2.1 Data Objects 8.2.2 Variables 8.2.3 Declaration of Variables 8.3 Elementary C++ Data Types 8.3.1 Integers

More information

6.096 Lab 1. Due: 7 January 12:30:00. September 20, 2011

6.096 Lab 1. Due: 7 January 12:30:00. September 20, 2011 6.096 Lab 1 Due: 7 January 1:30:00 September 0, 011 1 Additional Material 1.1 Constants A constant is an expressions with a fixed value. Kinds of constants: Literals: used to express particular values

More information

A First Book of C++ Chapter 2 Data Types, Declarations, and Displays

A First Book of C++ Chapter 2 Data Types, Declarations, and Displays A First Book of C++ Chapter 2 Data Types, Declarations, and Displays Objectives In this chapter, you will learn about: Data Types Arithmetic Operators Variables and Declarations Common Programming Errors

More information

INDEX. C programming Page 1 of 10. 5) Function. 1) Introduction to C Programming

INDEX. C programming Page 1 of 10. 5) Function. 1) Introduction to C Programming INDEX 1) Introduction to C Programming a. What is C? b. Getting started with C 2) Data Types, Variables, Constants a. Constants, Variables and Keywords b. Types of Variables c. C Keyword d. Types of C

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

Programming for MSc Part I

Programming for MSc Part I Herbert Martin Dietze University of Buckingham herbert@the-little-red-haired-girl.org July 24, 2001 Abstract The course introduces the C programming language and fundamental software development techniques.

More information

Indicates the end of data when the number of data is not known in advance Must be distinct from the data but be of the same type

Indicates the end of data when the number of data is not known in advance Must be distinct from the data but be of the same type Program Control Essentials of repetition Loop control variable Counts the number of repetitions in the counter-controlled loop Controls the execution of loop Sentinel value Indicates the end of data when

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

Introduction to Programming

Introduction to Programming Introduction to Programming SS 2012 Adrian Kacso, Univ. Siegen adriana.dkacsoa@duni-siegena.de Tel.: 0271/740-3966, Office: H-B 8406 Stand: April 25, 2012 Betriebssysteme / verteilte Systeme Introduction

More information

Adjusted/Modified by Nicole Tobias. Chapter 2: Basic Elements of C++

Adjusted/Modified by Nicole Tobias. Chapter 2: Basic Elements of C++ Adjusted/Modified by Nicole Tobias Chapter 2: Basic Elements of C++ Objectives In this chapter, you will: Become familiar with functions, special symbols, and identifiers in C++ Explore simple data types

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

E91 Embedded System. Intro

E91 Embedded System. Intro E91 Embedded System Intro Why embedded systems? Big bang-for-the-buck buck by adding some intelligence to systems. Embedded Systems are ubiquitous. Embedded Systems more common as prices drop, and power

More information

switch Multiple-Selection Statement

switch Multiple-Selection Statement switch Multiple-Selection Statement (This feature is rarely useful, although it s perfect for programming the iterative song The Twelve Days of Christmas!) If no match occurs, the default case is executed,

More information

C++ Programming: From Problem Analysis to Program Design, Fifth Edition. Chapter 2: Basic Elements of C++

C++ Programming: From Problem Analysis to Program Design, Fifth Edition. Chapter 2: Basic Elements of C++ C++ Programming: From Problem Analysis to Program Design, Fifth Edition Chapter 2: Basic Elements of C++ Objectives In this chapter, you will: Become familiar with the basic components of a C++ program,

More information

Going from Python to C

Going from Python to C Going from Python to C Darin Brezeale December 8, 2011 Python is a high-level, interpreted language. C has many of the same types of programming constructs as in Python: arrays, loops, conditionals, functions,

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

Control Structure. Pseudocode: Input number If number is even Then Print even Else print odd. Flowchart: Begin. End. Print Odd. number even?

Control Structure. Pseudocode: Input number If number is even Then Print even Else print odd. Flowchart: Begin. End. Print Odd. number even? Control Structure Normally, a program is executed in a sequential manner.however, in many cases, a program has to choose among alternative statements C++ provides constructs that enable the programmer

More information

Borland C++ Compiler: Operators

Borland C++ Compiler: Operators Introduction Borland C++ Compiler: Operators An operator is a symbol that specifies which operation to perform in a statement or expression. An operand is one of the inputs of an operator. For example,

More information

Dept. of CSE, IIT KGP

Dept. of CSE, IIT KGP Programming in C: Basics CS10001: Programming & Data Structures Pallab Dasgupta Professor, Dept. of Computer Sc. & Engg., Indian Institute of Technology Kharagpur Types of variable We must declare the

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

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

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 Language: Syntax. Introduction to C Language Overview, variables, Operators, Statements

Programming Language: Syntax. Introduction to C Language Overview, variables, Operators, Statements Programming Language: Syntax Introduction to C Language Overview, variables, Operators, Statements Based on slides McGraw-Hill Additional material 2004/2005 Lewis/Martin Modified by Diana Palsetia Syntax

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

3/13/2012. ESc101: Multiple statement execution using loops. Loops are used when instructions are repeated. while statement can be used for a loop

3/13/2012. ESc101: Multiple statement execution using loops. Loops are used when instructions are repeated. while statement can be used for a loop ESc101: Multiple statement execution using loops Instructor: Krithika Venkataramani Semester 2, 2011-2012 The content of most of these slides are taken from the lecture slides of Prof. Arnab Bhattacharya

More information

BHARATHIAR UNIVERSITY: COIMBATORE CENTRE FOR COLLABORATION OF INDUSTRY AND INSTITUTIONS(CCII) CERTIFICATE IN ADVANCED PROGRAMMING C++ LANGUAGE

BHARATHIAR UNIVERSITY: COIMBATORE CENTRE FOR COLLABORATION OF INDUSTRY AND INSTITUTIONS(CCII) CERTIFICATE IN ADVANCED PROGRAMMING C++ LANGUAGE Certificate in Advanced Programming - C++ Language Page 1 of 7 BHARATHIAR UNIVERSITY: COIMBATORE 641046 CENTRE FOR COLLABORATION OF INDUSTRY AND INSTITUTIONS(CCII) CERTIFICATE IN ADVANCED PROGRAMMING C++

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

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

INTRODUCTION TO FLOWCHARTING

INTRODUCTION TO FLOWCHARTING CHAPTER 1 INTRODUCTION TO FLOWCHARTING 1.0 Objectives 1.1 Introduction 1.2 Flowcharts 1.3 Types of Flowcharts 1.3.1 Types of flowchart 1.3.2 System flowcharts 1.4 Flowchart Symbols 1.5 Advantages of Flowcharts

More information

OSMIC. CSoft ware. C Language manual. Rev Copyright COSMIC Software 1999, 2003 All rights reserved.

OSMIC. CSoft ware. C Language manual. Rev Copyright COSMIC Software 1999, 2003 All rights reserved. OSMIC CSoft ware C Language manual Rev. 1.1 Copyright COSMIC Software 1999, 2003 All rights reserved. Table of Contents Preface Chapter 1 Historical Introduction Chapter 2 C Language Overview C Files...2-1

More information

Primitive Data Types Summer 2010 Margaret Reid-Miller

Primitive Data Types Summer 2010 Margaret Reid-Miller Primitive Data Types 15-110 Summer 2010 Margaret Reid-Miller Data Types Data stored in memory is a string of bits (0 or 1). What does 1000010 mean? 66? 'B'? 9.2E-44? How the computer interprets the string

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

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

6.087 Lecture 3 January 13, 2010

6.087 Lecture 3 January 13, 2010 6.087 Lecture 3 January 13, 2010 Review Blocks and Compound Statements Control Flow Conditional Statements Loops Functions Modular Programming Variable Scope Static Variables Register Variables 1 Review:

More information

M3-R4: PROGRAMMING AND PROBLEM SOLVING THROUGH C LANGUAGE

M3-R4: PROGRAMMING AND PROBLEM SOLVING THROUGH C LANGUAGE M3-R4: PROGRAMMING AND PROBLEM SOLVING THROUGH C LANGUAGE NOTE: IMPORTANT INSTRUCTIONS: 1. Question Paper in English and Hindi and Candidate can choose any one language. 2. In case of discrepancies in

More information

Basic C Syntax. Comp-206 : Introduction to Software Systems Lecture 10. Alexandre Denault Computer Science McGill University Fall 2006

Basic C Syntax. Comp-206 : Introduction to Software Systems Lecture 10. Alexandre Denault Computer Science McGill University Fall 2006 Basic C Syntax Comp-206 : Introduction to Software Systems Lecture 10 Alexandre Denault Computer Science McGill University Fall 2006 Next Week I'm away for the week. I'll still check my mails though. No

More information

NRI Institute of Technology Principles of Programming Languages III B.Tech I Sem (R09)-CSE

NRI Institute of Technology Principles of Programming Languages III B.Tech I Sem (R09)-CSE Unit-4 Expressions and Assignment Statements Introduction Expressions are the fundamental means of specifying computations in a programming language. To understand expression evaluation, need to be familiar

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

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

Computers process data under the control of sets of instructions called computer programs.

Computers process data under the control of sets of instructions called computer programs. Introduction Computer is a device capable of performing computations and making logical decisions at speeds millions and even billions of times faster than human beings. Computers process data under the

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

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

School of Informatics, University of Edinburgh

School of Informatics, University of Edinburgh CS1Ah Lecture Note 5 Java Expressions Many Java statements can contain expressions, which are program phrases that tell how to compute a data value. Expressions can involve arithmetic calculation and method

More information

Which of the following is the correct operator to compare two variables? A. := B. = C. equal D. ==

Which of the following is the correct operator to compare two variables? A. := B. = C. equal D. == Group 1 Question 1. What is the correct value to return to the operating system upon the successful completion of a program? A. -1 B. 1 C. 0 D. Programs do not return a value. Question 2. What is the only

More information

PIC Microcontrollers The basics of C programming language

PIC Microcontrollers The basics of C programming language Page 1 / 28 Page 2 / 28 Table of contents PROGRAMMING LANGUAGES...3 ADVANTAGES OF HIGHER PROGRAMMING LANGUAGES...6 PREPROCESSOR... 6 PREPROCESSOR DIRECTIVE # include... 7 PREPROCESSOR DIRECTIVE # define...7

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

Chapter 4 Operators & Arithmetic

Chapter 4 Operators & Arithmetic Chapter 4 Operators & Arithmetic 4-1 Arithmetic in C++ Arithmetic expressions can be made up of constants, variables, operators and parentheses. The arithmetic operators in C++ are as follows + (addition)

More information

appendix d The C Programming Language

appendix d The C Programming Language D.1 Overview This appendix is a C reference manual oriented toward the novice C programmer. It covers a significant portion of the language, including material not covered in the main text of this book.

More information

C programming. Intro to syntax & basic operations

C programming. Intro to syntax & basic operations C programming Intro to syntax & basic operations Example 1: simple calculation with I/O Program, line by line Line 1: preprocessor directive; used to incorporate code from existing library not actually

More information

Repetition and Loops. Additional Python constructs that allow us to effect the (1) order and (2) number of times that program statements are executed.

Repetition and Loops. Additional Python constructs that allow us to effect the (1) order and (2) number of times that program statements are executed. New Topic Repetition and Loops Additional Python constructs that allow us to effect the (1) order and (2) number of times that program statements are executed. These constructs are the 1. while loop and

More information

MGM s JNEC Question Bank Subject: Computer Engineering

MGM s JNEC Question Bank Subject: Computer Engineering MGM s JNEC Question Bank Subject: Computer Engineering 1. All of the following are examples of computer input units EXCEPT: a) Scanner b) Speaker c) Bar code reader d) Keyboard Answer: b 2. Which of the

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

MIT Aurangabad FE Computer Engineering

MIT Aurangabad FE Computer Engineering MIT Aurangabad FE Computer Engineering Unit 1: Introduction to C 1. The symbol # is called a. Header file c. include b. Preprocessor d. semicolon 2. The size of integer number is limited to a. -32768 to

More information

Today s topics. Java programs. Java Virtual Machine (JVM) Bytecodes. HelloWorld.java javac HelloWorld.class

Today s topics. Java programs. Java Virtual Machine (JVM) Bytecodes. HelloWorld.java javac HelloWorld.class Today s topics Java programs Parsing Java Programming Notes from Tammy Bailey Reading Great Ideas, Chapter 3 & 4 Java programs are created as text files using a text editor (like emacs) Save to disk with.java

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

Part IA Computing Course Tutorial Guide to C++ Programming

Part IA Computing Course Tutorial Guide to C++ Programming Part IA Computing Course Tutorial Guide to C++ Programming Roberto Cipolla Department of Engineering University of Cambridge September 1, 2004 This document provides an introduction to computing and the

More information

Chapter 4 C Program Control

Chapter 4 C Program Control Chapter 4 C Program Control Objectives of this chapter: Repetitions will be considered in greater detail for.. repetition do while repetition Also multiple selection switch case statement will be learned.

More information

LECTURE NOTE on PROGRAMMING IN C

LECTURE NOTE on PROGRAMMING IN C LECTURE NOTE on PROGRAMMING IN C COURSE CODE: MCA 101 By Asst. Professor Mrs Etuari Oram Asst. Prof. Mr Bighnaraj Naik SYLLABUS Module I C Language Fundamentals. Character set, Identifiers, keyword, data

More information

Birla Institute of Technology &Science, Pilani Computer Programming (CS F111) Second Semester Lab-3 (Introduction to C Programming Language)

Birla Institute of Technology &Science, Pilani Computer Programming (CS F111) Second Semester Lab-3 (Introduction to C Programming Language) Topics to be covered: 1. C Program structure and execution 2. Data type 3. Reading input and printing output 4. Expression 5. Operator precedency 6. Typecasting Birla Institute of Technology &Science,

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

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

Introduction to Programming Block Tutorial C/C++

Introduction to Programming Block Tutorial C/C++ Michael Bader Master s Program Computational Science and Engineering C/C++ Tutorial Overview From Maple to C Variables, Operators, Statements Functions: declaration, definition, parameters Arrays and Pointers

More information

,!7IA3C1-dcahfj!:t;K;k;K;k. Addison-Wesley s JavaScript Reference Card. Kathleen M. Goelz and Carol J. Schwartz, Rutgers University VARIABLES

,!7IA3C1-dcahfj!:t;K;k;K;k. Addison-Wesley s JavaScript Reference Card. Kathleen M. Goelz and Carol J. Schwartz, Rutgers University VARIABLES Addison-Wesley s JavaScript Reference Card Kathleen M. Goelz and Carol J. Schwartz, Rutgers University Javascript: A scripting language designed to be integrated into HTML code to produce enhanced, dynamic,

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

Reading. C Programming Language. Basic syntax Whitespaces. Whitespaces (cont d) #include. Basic syntax Comments

Reading. C Programming Language. Basic syntax Whitespaces. Whitespaces (cont d) #include. Basic syntax Comments Reading C Programming Language Types, operators, expressions Control flow, functions Basic IO K&R Chapter 2 Types, Operators, and Expressions K&R Chapter 3 Control Flow K&R Chapter 7 Basic I/O NEWS Assignment

More information

Lecture 1 Notes: Introduction

Lecture 1 Notes: Introduction Introduction to C++ January 4, 2011 Massachusetts Institute of Technology 6.096 Lecture 1 Notes: Introduction 1 Compiled Languages and C++ 1.1 Why Use a Language Like C++? At its core, a computer is just

More information

Introduction to Problem Solving Techniques

Introduction to Problem Solving Techniques UNIT 1 Introduction to Problem Solving Techniques Structure 1.0 Introduction 1.1 Procedure (steps involved in problem solving) 1.2 Algorithm 1.3 Flow Chart 1.4 Symbols used in Flow Charts 1.5 Pseudo Code

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

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

About the Tutorial. Audience. Prerequisites. Copyright & Disclaimer

About the Tutorial. Audience. Prerequisites. Copyright & Disclaimer About the Tutorial Computer programming is the act of writing computer programs, which are a sequence of instructions written using a Computer Programming Language to perform a specified task by the computer.

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

3) Some coders debug their programs by placing comment symbols on some codes instead of deleting it. How does this aid in debugging?

3) Some coders debug their programs by placing comment symbols on some codes instead of deleting it. How does this aid in debugging? Freshers Club Important 100 C Interview Questions & Answers 1) How do you construct an increment statement or decrement statement in C? There are actually two ways you can do this. One is to use the increment

More information

z = x + y * z / 4 % 2-1

z = x + y * z / 4 % 2-1 1.Which of the following statements should be used to obtain a remainder after dividing 3.14 by 2.1? A. rem = 3.14 % 2.1; B. rem = modf(3.14, 2.1); C. rem = fmod(3.14, 2.1); D. Remainder cannot be obtain

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

C programming: exercise sheet L2-STUE (2011-2012)

C programming: exercise sheet L2-STUE (2011-2012) C programming: exercise sheet L2-STUE (2011-2012) Algorithms and Flowcharts Exercise 1: comparison Write the flowchart and associated algorithm that compare two numbers a and b. Exercise 2: 2 nd order

More information

CSI 333 Lecture 2 Introduction to C: Part I 2 1 / 16

CSI 333 Lecture 2 Introduction to C: Part I 2 1 / 16 CSI 333 Lecture 2 Introduction to C: Part I 2 1 / 16 Basics of C Remark: Skim Chapters 1 through 6 of Deitel & Deitel. You will notice the following: C is (more or less) a subset of Java. (So, you are

More information

The PCAT Programming Language Reference Manual

The PCAT Programming Language Reference Manual The PCAT Programming Language Reference Manual Andrew Tolmach and Jingke Li Dept. of Computer Science Portland State University (revised October 8, 2004) 1 Introduction The PCAT language (Pascal Clone

More information

Chapter 2: Basic Elements of C++

Chapter 2: Basic Elements of C++ Chapter 2: Basic Elements of C++ Objectives In this chapter, you will: Become familiar with functions, special symbols, and identifiers in C++ Explore simple data types Discover how a program evaluates

More information

The IC Language Specification. Spring 2006 Cornell University

The IC Language Specification. Spring 2006 Cornell University The IC Language Specification Spring 2006 Cornell University The IC language is a simple object-oriented language that we will use in the CS413 project. The goal is to build a complete optimizing compiler

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

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

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