Programming in C and Data Structures [15PCD13/23] 1. PROGRAMMING IN C AND DATA STRUCTURES [As per Choice Based Credit System (CBCS) scheme]

Size: px
Start display at page:

Download "Programming in C and Data Structures [15PCD13/23] 1. PROGRAMMING IN C AND DATA STRUCTURES [As per Choice Based Credit System (CBCS) scheme]"

Transcription

1 Programming in C and Data Structures [15PCD13/23] 1 PROGRAMMING IN C AND DATA STRUCTURES [As per Choice Based Credit System (CBCS) scheme] Course objectives: The objectives of this course is to make students to learn basic principles of Problem solving, implementing through C programming language and to design & develop programming skills. To gain knowledge of data structures and their applications. Course outcomes: On completion of this course, students are able to Achieve Knowledge of design and development of C problem solving skills. Understand the basic principles of Programming in C language Design and develop modular programming skills. Effective utilization of memory using pointer technology Understands the basic concepts of pointers and data structures. Question paper pattern: The question paper will have ten questions. Each full Question consisting of 16 marks There will be 2 full questions (with a maximum of four sub questions) from each module. Each full question will have sub questions covering all the topics under a module. The students will have to answer 5 full questions, selecting one full question from each module.

2 Programming in C and Data Structures [15PCD13/23] 2 MODULE 1 INTRODUCTION TO C LANGUAGE Brief History of C Language and its importance. C is a general-purpose language which has been closely associated with the UNIX operating system for which it was developed - since the system and most of the programs that run it are written in C. Many of the important ideas of C stem from the language BCPL, developed by Martin Richards. The influence of BCPL on C proceeded indirectly through the language B, which was written by Ken Thompson in 1970 at Bell Labs, for the first UNIX system on a DEC PDP-7. BCPL and B are "type less" languages whereas C provides a variety of data types. In 1972 Dennis Ritchie at Bell Labs writes C and in 1978 the publication of The C Programming Language by Kernighan & Ritchie caused a revolution in the computing world. In 1983, the American National Standards Institute (ANSI) established a committee to provide a modern, comprehensive definition of C. The resulting definition, the ANSI standard, or "ANSI C", was completed late C was initially used for system development work, in particular the programs that make-up the operating system. Why use C? Mainly because it produces code that runs nearly as fast as code written in assembly language. Some examples of the use of C might be: 1. Operating Systems 2. Language Compilers 3. Assemblers 4. Text Editors 5. Print Spoolers 6. Network Drivers 7. Modern Programs 8. Data Bases 9. Language Interpreters 10. Utilities In recent years C has been used as a general-purpose language because of its popularity with programmers. It is not the world's easiest language to learn and you will certainly benefit if you are not learning C as your first programming language! 1. Pseudo code Solution to the problem Pseudo code: is a restatement of the problem as a list of steps, in an English like format describing what must be done to solve it. Pseudocode is a simple way of writing programming code in English. Pseudocode is not an actual programming language. It uses short phrases to write code for programs before you actually create it in a specific language.

3 Programming in C and Data Structures [15PCD13/23] 3 Problem : Write a Pseudo code to Calculate Pay Begin input hours input rate pay = hours * rate print pay End Problem : Write a Pseudo code to Calculate Sum of 2 Numbers Begin input x, y sum = x + y print sum End Problem : Write a Pseudo code to Calculate Average of 3 Numbers Begin input x input y input z sum = x + y + z avg = sum / 3.0 print avg End Problem Solving in C Above Diagram shows general problem solving procedure. Starting with Statement of the problem and writing Algorithm/Pseudo code. Then Program is written using any of the Programming languages. Each time program is executed which takes inputs and gives certain output depending on the program. Algorithm : Algorithms are the set of well defined instructions in sequence to solve a program. An algorithm should always have a clear stopping point. It can be defined as step by step procedure to solve a problem in a finite amount of time. Qualities of a good algorithm 1. Inputs and outputs should be defined precisely. 2. Each step in algorithm should be clear and unambiguous. 3. Algorithm should be most effective among many different ways to solve a problem. 4. An algorithm shouldn't have computer code. Instead, the algorithm should be written in such a way that, it can be used in similar programming languages.

4 Programming in C and Data Structures [15PCD13/23] 4 Write an algorithm to add two numbers entered by user. Algorithm : To add two numbers entered by user Step 1: [Start] Start Step 2: [Declaration Section] Declare variables num1, num2 and sum. Step 3: [Input the values] Read values num1 and num2. Step 4: [Addition operation] Add num1 and num2 and assign the result to sum. sum num1+num2 Step 5: [print the result] Display sum Step 6: [Terminate] Stop Write an algorithm to find the largest among three different numbers entered by user. Algorithm : To find the largest among three different numbers entered by user Step 1: [Start] Start Step 2: [Declaration Section] Declare variables a,b and c. Step 3: [Input the values] Read variables a,b and c. Step 4: [ Finding the Biggest of 3 numbers ] If a>b If a>c Display a is the largest number. Else Display c is the largest number. Else If b>c Display b is the largest number. Else Display c is the greatest number. Step 5: [Terminate] Stop Write an algorithm to find the factorial of a number entered by user. Algorithm : to find the factorial of a number entered by user Step 1: [Start] Start Step 2: [Declaration Section] Declare variables n,factorial and i. Step 3: [Initialize variables] factorial 1 i 1 Step 4: [Inputing the number] Read value of n Step 5: [Calculate the factorial ] Repeat the steps until i=n 5.1: factorial factorial*i 5.2: i i+1 Step 6: [Print the Result ] Display factorial Step 7: [Terminate ] Stop

5 2. Basic Concepts of C Program. Programming in C and Data Structures [15PCD13/23] 5 C program consists of one or more functions or code modules. These are essentially groups of instructions that are to be executed as a unit in a given order and that can be referenced by a unique name. Each C program must contain a main() function. This is the first function called when the program starts to run. Note that while "main" is not a C keyword and hence not reserved it should be used only in this context. A C program is traditionally arranged in the following order but not strictly as a rule. /* Documentation Section*/ Pre-processor Directives Macros Function prototypes and global data declarations main() Local Declarations; Statements; User defined functions Consider first a simple C program which simply prints a line of text to the computer screen. This is traditionally the first C program you will see and is commonly called the Hello World program for obvious reasons. #include <stdio.h> /* This is how comments are implemented in C to comment out a block of text */ // or like this for a single line comment printf( "Hello World\n" ) ; As you can see this program consists of just one function the mandatory main function. The parentheses, ( ), after the word main indicate a function while the curly braces,, are used to denote a block of code -- in this case the sequence of instructions that make up the function. Comments are contained within a /*... */ pair in the case of a block comment or a double forward slash, //, may be used to comment out the remains of a single line of test. The line printf("hello World\n " ) ; is the only C statement in the program and must be terminated by a semi-colon. The statement calls a function called printf which causes its argument, the string of text within the quotation marks, to be printed to the screen. The characters \n are not printed as these characters are interpreted as special characters by the printf function in this case printing out a newline on the screen. These characters are called escape sequences in C and cause special actions to occur and are preceded always by the backslash character, \. All C compiler include a library of standard C functions such as printf which allow the programmer to carry out routine tasks such as I/O, maths operations, etc. but which are not part of the C language, the compiled C code merely being provided with the compiler in a standard form.

6 Programming in C and Data Structures [15PCD13/23] 6 Header files must be included which contain prototypes for the standard library functions and declarations for the various variables or constants needed. These are normally denoted by a.h extension and are processed automatically by a program called the Preprocessor prior to the actual compilation of the C program. The line #include <stdio.h> Instructs the pre-processor to include the file stdio.h into the program before compilation so that the definitions for the standard input/output functions including printf will be present for the compiler. The angle braces denote that the compiler should look in the default INCLUDE directory for this file. A pair of double quotes indicate that the compiler should search in the specified path e.g. #include d:\myfile.h Note: C is case sensitive i.e. printf() and Printf() would be regarded as two different functions. C language Preliminaries C language became popular because of the following reasons. C is a robust language, which consists of number of built-in functions and operators can be used to write any complex program Programs written in c are executed fast compared to other languages. C language is highly portable C language is well suited for structured programming. C is a simple language and easy to learn. Character Set The characters that can be used to form words, numbers and expressions depend upon the computer on which the program is run. The characters in C are grouped into the following categories. 1. Letters A-Z, a-z 2. Digits Special characters operators(+, -, /, +, %, <, >,..etc.), punctuations (,,., :, ;,..etc.) 4. White Spaces Blank Space, Horizontal tab, Carriage return, New line, Form feed TOKENS A token is a smallest element of a C program. One or more characters are grouped in sequence to form meaningful words. These meaningful words are called tokens. The tokens are broadly classified as follows Keywords ex: if, for, while..etc. Identifiers ex: sum, length..etc. Constants ex: 10, 10.5, 'a', "sri"...etc. Operators ex: + - * /..etc. Special symbols ex: [ ], ( ),...etc.

7 Programming in C and Data Structures [15PCD13/23] 7 KEYWORDS Keywords are tokens which are used for their intended purpose only. Each keyword has fixed meaning and that cannot be changed by user. Hence, they are also called reserved-words. Rules for using keywords Keywords cannot be used as a variable or function. All keywords should be written in lower letters. Some keywords are as listed below break case char const continue default do double else float for if int long register return short signed sizeof struct switch typedef unsigned void while IDENTIFIER As the name indicates, identifier is used to identify various entities of program such as variables, constants, functions etc. In other words, an identifier is a word consisting of sequence of Letters Digits or "_"(underscore) For ex: area, length, breadth CONSTANTS A constant is an identifier whose value remains fixed throughout the execution of the program. The constants cannot be modified in the program. For example: 1, , z, girishmantha" Different types of constants are: 1) Integer Constant An integer is a whole number without any fraction part. There are 3 types of integer constants: Decimal constants ( ) For ex: 0, -9, 22 Octal constants ( ) For ex: 021, 077, 033 Hexadecimal constants ( A B C D E F) For ex: 0x7f, 0x2a, 0x521 2) Floating Point Constant The floating point constant is a real number. The floating point constants can be represented using 2 forms: Fractional Form A floating point number represented using fractional form has an integer part followed by a dot and a fractional part. For ex: 0.5, ii) Scientific Notation (Exponent Form) The floating point number represented using scientific notation has three parts namely: mantissa, E and exponent. For ex: 9.86E3 imply 9.86*103 3) Character Constant A symbol enclosed within a pair of single quotes(') is called a character constant.

8 Programming in C and Data Structures [15PCD13/23] 8 Each character is associated with a unique value called an ASCII (American Standard Code for Information Interchange) code. For ex: '9', 'a', '\n' 4) String Constant A sequence of characters enclosed within a pair of double quotes( ) is called a string constant. The string always ends with NULL (denoted by \0) character. For ex: "9" "a" "sri" "\n" 5) Escape Sequence Characters An escape sequence character begins with a backslash and is followed by one character. A backslash (\) along with some characters give rise to special print effects by changing (escaping) the meaning of some characters. The complete set of escape sequences are: Escape Sequences Character \b Backspace \f Form feed \n Newline \r Return \t Horizontal tab \v Vertical tab \\ Backslash \' Single quotation mark \" Double quotation mark \? Question mark \0 Null character DATA TYPES The data type defines the type of data stored in a memory-location. 1) int An int is a keyword which is used to define integers. 2) float A float is a keyword which is used to define floating point numbers. 3) double A double is a keyword used to define long floating point numbers. 4) char A char is a keyword which is used to define single character. 5) void void is an empty data type. Since no value is associated with this data type, it does not occupy any space in the memory. This is normally used in functions to indicate that the function does not return any value. Range of data types Data type Bytes Range of data type char 1 bytes -128 to 127 int 2 bytes -32, 768 to 32,767 float 4 bytes 3.4E-38 to 3.4E38 double 8 bytes 1.7E-308 to 1.7E308

9 Programming in C and Data Structures [15PCD13/23] 9 3. Declaration, Assignment and Print Statements. Variable A variable is an identifier whose value can be changed during execution of the program. In other words, a variable is a name given to a memory-location where the data can be stored. Using the variable-name, the data can be stored in a memory-location and accessed or manipulated Rules for defining a variable 1) The first character in the variable should be a letter or an underscore 2) The first character can be followed by letters or digits or underscore 3) No extra symbols are allowed (other than letters, digits and underscore) 4) Length of a variable can be up to a maximum of 31 characters 5) Keywords should not be used as variable-names Valid variables: a, principle_amount, sum_of_digits Invalid variables: 3fact //violates rule 1 sum= sum-of-digits 62$ //violates rule 3 for int if //violates rule 5 Initialising Variables Syntax :- type var-name = constant ; For Example :- char ch = 'a' ; double d = ; int i, j = 20 ; /* note in this case i is not initialized */ Assignment Operator int x ; x = 20 ; Some common notation :- lvalue -- left hand side of an assignment operation rvalue -- right hand side of an assignment operation Type Conversions :- the value of the right hand side of an assignment is converted to the type of the lvalue. This may sometimes yield compiler warnings if information is lost in the conversion. For Example :- int x ; char ch ; float f ; ch = x ; /* ch is assigned lower 8 bits of x, the remaining bits are discarded so we have a possible information loss */ x = f ; /* x is assigned non fractional part of f only within int range, information loss possible */ f = x ; /* value of x is converted to floating point */ Multiple assignments are possible to any degree in C, the assignment operator has right to left associativity which means that the rightmost expression is evaluated first. For Example :- x = y = z = 100 ;

10 Programming in C and Data Structures [15PCD13/23] 10 In this case the expression z = 100 is carried out first. This causes the value 100 to be placed in z with the value of the whole expression being 100 also. This expression value is then taken and assigned by the next assignment operator on the left i.e. x = y = ( z = 100 ) ; printf( ) The syntax is shown below: n=printf("format-string", variable-list); where format-string contains one or more format-specifiers variable-list contains names of variables The printf() function is used for formatted output and uses a control string which is made up of a series of format specifiers to govern how it prints out the values of the variables or constants required. The more common format specifiers are given below %c character %f floating point %d signed integer %lf double floating point %i signed integer %e exponential notation %u unsigned integer %s string %ld signed long %x unsigned hexadecimal %lu unsigned long %o unsigned octal %% prints a % sign For Example:- int i ; printf( "%d", i ) ; The printf( ) function takes a variable number of arguments. In the above example two arguments are required, the format string and the variable i. The value of i is substituted for the format specifier %d which simply specifies how the value is to be displayed, in this case as a signed integer. Some further examples :- int i = 10, j = 20 ; char ch = 'a' ; double f = ; printf( "%d + %d", i, j ) ; /* values are substituted from the variable list in order as required */ printf( "%c", ch ) ; printf( "%s", "Hello World\n" ) ; printf( "The value of f is : %lf", f );/*Output as : */ printf( "f in exponential form : %e", f ) ; /* Output as : e+4 scanf() This function is similar to the printf function except that it is used for formatted input. Syntax is shown below: n=scanf("format-string", address-list); where format-string contains one or more format-specifiers address-list is a list of variables. Each variable name must be preceded by & For Example :- int i, d ; char c ; float f ; scanf( "%d", &i ) ; scanf( "%d %c %f", &d, &c, &f ) ; /* e.g. type "10_x_1.234RET" */

11 Programming in C and Data Structures [15PCD13/23] 11 scanf( "%d:%c", &i, &c ) ; /* e.g. type "10:xRET" */ The & character is the address of operator in C, it returns the address in memory of the variable it acts on. (Aside : This is because C functions are nominally call--by--value. Thus in order to change the value of a calling parameter we must tell the function exactly where the variable resides in memory and so allow the function to alter it directly rather than to uselessly alter a copy of it. ) Note that while the space and newline characters are normally used as delimiters between input fields the actual delimiters specified in the format string of the scanf statement must be reproduced at the keyboard faithfully as in the case of the last sample call. If this is not done the program can produce somewhat erratic results! The scanf function has a return value which represents the number of fields it was able to convert successfully. For Example :- num = scanf( %c %d, &ch, &i ); This scanf call requires two fields, a character and an integer, to be read in so the value placed in num after the call should be 2 if this was successful. However if the input was a bc then the first character field will be read correctly as a but the integer field will not be converted correctly as the function cannot reconcile bc as an integer. Thus the function will return 1 indicating that one field was successfully converted. Thus to be safe the return value of the scanf function should be checked always and some appropriate action taken if the value is incorrect. #include<stdio.h> int age; printf( enter your age: \n ); scanf( %d, age); printf( your age is = %d years, age); enter your age: 21 your age is = 21 years 4. Types of operators and expressions One of the most important features of C is that it has a very rich set of built in operators including arithmetic, relational, logical, and bitwise operators. An operator can be any symbol like + - * / that specifies what operation need to be performed on the data. For ex: + indicates add operation * indicates multiplication operation An operand can be a constant or a variable. An expression is combination of operands and operator that reduces to a single value. For ex: Consider the following expression a + b here a and b are operands, while + is an operator

12 Programming in C and Data Structures [15PCD13/23] 12 Arithmetic Operators + - * / --- same rules as mathematics with * and / being evaluated before + and -. % -- modulus / remainder operator For Example:- int a = 5, b = 2, x ; float c = 5.0, d = 2.0, f ; x = a / b ; // integer division, x = 2. f = c / d ; // floating point division, f = 2.5. x = 5 % 2 ; // remainder operator, x = 1. x = * 6 / 2-1 ;// x=15,* and / evaluated ahead of + and -. Note that parentheses may be used to clarify or modify the evaluation of expressions of any type in C in the same way as in normal arithmetic. x = 7 + ( 3 * 6 / 2 ) - 1 ; // clarifies order of evaluation without penalty x = ( ) * 6 / ( 2-1 ) ; // changes order of evaluation, x = 60 now. Increment and Decrement Operators INCREMENT OPERATOR ++ is an increment operator. As the name indicates, increment means increase, i.e. this operator is used to increase the value of a variable by 1. For example: If b=5 then b++ or ++b; // b becomes 6 The increment operator is classified into 2 categories: 1) Post increment Ex: b++ 2) Pre increment Ex: ++b As the name indicates, post-increment means first use the value of variable and then increase the value of variable by 1. As the name indicates, pre-increment means first increase the value of variable by 1 and then use the updated value of variable. For ex: If x is 10, then z= x++; sets z to 10 but z = ++x; sets z to 11 Example: Program to illustrate the use of increment operators. #include<stdio.h> int x=10,y = 10, z ; z= x++; printf( z=%d x= %d\n, z, x); z = ++y; printf( z=%d y= %d, z, y); z=10 x=11 z=11 y=11

13 Programming in C and Data Structures [15PCD13/23] 13 DECREMENT OPERATOR -- is a decrement operator. As the name indicates, decrement means decrease, i.e. this operator is used to decrease the value of a variable by 1. For example: If b=5 then b-- or --b; // b becomes 4 Similar to increment operator, the decrement operator is classified into 2 categories: 1) Post decrement Ex: b-- 2) Pre decrement Ex: --b For ex: If x is 10, then z= x--; sets z to 10, but z = --x; sets z to 9. Example: Program to illustrate the use of decrement operators. int x=10,y = 10, z ; z= x--; printf( z=%d x= %d\n, z, x); z = --y; printf( z=%d y= %d, z, y); z=10 x=9 z=9 y=9 ASSIGNMENT OPERATOR The most common assignment operator is =. This operator assigns the value in right side to the left side. The syntax is shown below: variable=expression; For ex: c=5; //5 is assigned to c b=c; //value of c is assigned to b 5=c; // Error! 5 is a constant. The operators such as +=,*= are called shorthand assignment operators. For ex, a=a+10: can be written as a+=10; In the same way, we have: Operator Example Same as -= a-=b a=a-b *= a*=b a=a*b /= a/=b a=a/b %= a%=b a=a%b RELATIONAL OPERATORS Relational operators are used to find the relationship between two operands. The output of relational expression is either true(1) or false(0). For example a>b //If a is greater than b, then a>b returns 1 else a>b returns 0. The 2 operands may be constants, variables or expressions. There are 6 relational operators:

14 Programming in C and Data Structures [15PCD13/23] 14 Operator Meaning of Operator Example > Greater than 5>3 returns true (1) < Less than 5<3 returns false (0) >= Greater than or equal to 5>=3 returns true (1) <= Less than or equal to 5<=3 return false (0) == Equal to 5==3 returns false (0)!= Not equal to 5!=3 returns true(1) For ex: Condition Return values 2>1 1 (or true) 2>3 0 (or false) 3+2<6 1 (or true) Example: Program to illustrate the use of all relational operators. #include<stdio.h> printf( 4>5 : %d \n, 4>5); printf( 4>=5 : %d \n, 4>=5); printf( 4<5 : %d \n, 4<5); printf( 4<=5 : %d \n, 4<=5); printf( 4==5 : %d \n, 4==5); printf( 4!=5 : %d, 4!=5); 4>5 : 0 4>=5 : 0 4<5 : 1 4<=5 :1 4==5 : 0 4!=5 : 1 LOGICAL OPERATORS These operators are used to perform logical operations like negation, conjunction and disjunction. The output of logical expression is either true(1) or false(0). There are 3 logical operators: Operator Meaning Example && Logical AND If c=5 and d=2 then ((c==5)&&(d>5)) returns false. Logical OR If c=5 and d=2 then ((c==5) (d>5)) returns true.! Logical NOT If c=5 then!(c==5) returns false. All non zero values(i.e. 1, -1, 2, -2) will be treated as true. While zero value(i.e. 0 ) will be treated as false. Truth table A B A&&B A B!A Example: Program to illustrate the use of all logical operators.

15 Programming in C and Data Structures [15PCD13/23] 15 #include<stdio.h> printf( 7 && 0 : %d \n, 7 && 0 ); printf( 7 0 : %d \n, 7 0 ); printf(!0 : %d,!0 ); 7 && 0 : : 1!0 : 1 Example: Program to illustrate the use of both relational & Logical operators. #include<stdio.h> printf( 5>3 && 5<10 : %d \n, 5>3 && 5<10); printf( 8<5 5= =5 : % d \n, 8<5 5==5); printf(!(8 = =8) : %d,!(8==8) ; 5>3 && 5<10 : 1 8<5 5= =5 : 1!(8 = =8) : 0 CONDITIONAL OPERATOR The conditional operator is also called ternary operator it takes three operands. Conditional operators are used for decision making in C. The syntax is shown below: (exp1)? exp2: exp3; where exp1 is an expression evaluated to true or false; If exp1 is evaluated to true, exp2 is executed; If exp1 is evaluated to false, exp3 is executed. Example: Program to find largest of 2 numbers using conditional operator. #include<stdio.h> int a,b, max ; printf( enter 2 distinct numbers \n ); scanf( %d %d, &a, &b); max=(a>b)? a : b; printf( largest number =%d, max); enter 2 distinct numbers 3 4 largest number = 4 BITWISE OPERATORS These operators are used to perform logical operation (and, or, not) on individual bits of a binary number. There are 6 bitwise operators: Operators Meaning of operators & Bitwise AND Bitwise OR ^ Bitwise exclusive OR ~ Bitwise complement

16 << Shift left >> Shift right Programming in C and Data Structures [15PCD13/23] 16 TYPE CONVERSION Type conversion is used to convert data of one type to data of another type. Type conversion is of 2 types as shown in below figure: IMPLICIT CONVERSION If a compiler converts one type of data into another type of data automatically, it is known as implicit conversions. There is no data loss in implicit conversion. The conversion always takes place from lower rank to higher rank. For ex, int to float as shown in the above datatype hierarchy. For ex: int a = 22, b=11; float c = a; //c becomes float d=b/c=11/ = / = If one operand type is same as other operand type, no conversion takes place and type of result remains same as the operands i.e. int+int=int float+float=float Conversion rules are as follows: If either operand is long double, convert the other to long double. Otherwise, if either operand is double, convert the other to double. Otherwise, if either operand is float, convert the other to float. Otherwise, convert char and short to int. Then, if either operand is long, convert the other to long. Example: Program to illustrate implicit conversion.

17 Programming in C and Data Structures [15PCD13/23] 17 #include<stdio.h> int a = 22, b=11; float d ; d=b/c; printf("d Value is : %f ", d ); d Value is : EXPLICIT CONVERSION When the data of one type is converted explicitly to another type with the help of some predefine functions, it is called as explicit conversion. There may be data loss in this process because the conversion is forceful. The syntax is shown below: data_type1 v1; data_type2 v2= (data_type2) v1; where v1 can be expression or variable For ex: float b= ; int c = 22; float d=b/(float)c= / = Example: Program to illustrate explicit conversion. #include<stdio.h> float b= ; int c = 22; float d; d=b/(float)c; printf("d Value is : %f ", d ); d Value is : THE PRECEDENCE OF OPERATORS The order in which different operators are used to evaluate an expression is called precedence of operators. Precedence Table

18 Programming in C and Data Structures [15PCD13/23] 18 Example to understand the operator precedence available in C programming language. #include<stdio.h> int a = 20; int b = 10; int c = 15; int d = 5; int e; e = (a + b) * c / d; // ( 30 * 15 ) / 5 printf("value of (a + b) * c / d is : %d \n", e ); e = ((a + b) * c) / d; // (30 * 15 ) / 5 printf("value of ((a + b) * c) / d is : %d \n", e ); e = (a + b) * (c / d); // (30) * (15/5) printf("value of (a + b) * (c / d) is : %d \n", e ); e = a + (b * c) / d; // 20 + (150/5) printf("value of a + (b * c) / d is : %d ", e ); Value of (a + b) * c / d is : 90 Value of ((a + b) * c) / d is : 90 Value of (a + b) * (c / d) is : 90 Value of a + (b * c) / d is : 50 ~~ End of Module 1 ~~

Features of C. Portable Procedural / Modular Structured Language Statically typed Middle level language

Features of C. Portable Procedural / Modular Structured Language Statically typed Middle level language 1 History C is a general-purpose, high-level language that was originally developed by Dennis M. Ritchie to develop the UNIX operating system at Bell Labs. C was originally first implemented on the DEC

More information

UNIT - I. Introduction to C Programming. BY A. Vijay Bharath

UNIT - I. Introduction to C Programming. BY A. Vijay Bharath UNIT - I Introduction to C Programming Introduction to C C was originally developed in the year 1970s by Dennis Ritchie at Bell Laboratories, Inc. C is a general-purpose programming language. It has been

More information

UNIT- 3 Introduction to C++

UNIT- 3 Introduction to C++ UNIT- 3 Introduction to C++ C++ Character Sets: Letters A-Z, a-z Digits 0-9 Special Symbols Space + - * / ^ \ ( ) [ ] =!= . $, ; : %! &? _ # = @ White Spaces Blank spaces, horizontal tab, carriage

More information

Work relative to other classes

Work relative to other classes Work relative to other classes 1 Hours/week on projects 2 C BOOTCAMP DAY 1 CS3600, Northeastern University Slides adapted from Anandha Gopalan s CS132 course at Univ. of Pittsburgh Overview C: A language

More information

Computers Programming Course 5. Iulian Năstac

Computers Programming Course 5. Iulian Năstac Computers Programming Course 5 Iulian Năstac Recap from previous course Classification of the programming languages High level (Ada, Pascal, Fortran, etc.) programming languages with strong abstraction

More information

Fundamental of C programming. - Ompal Singh

Fundamental of C programming. - Ompal Singh Fundamental of C programming - Ompal Singh HISTORY OF C LANGUAGE IN 1960 ALGOL BY INTERNATIONAL COMMITTEE. IT WAS TOO GENERAL AND ABSTRUCT. IN 1963 CPL(COMBINED PROGRAMMING LANGUAGE) WAS DEVELOPED AT CAMBRIDGE

More information

Data Types and Variables in C language

Data Types and Variables in C language Data Types and Variables in C language Basic structure of C programming To write a C program, we first create functions and then put them together. A C program may contain one or more sections. They are

More information

P.E.S. INSTITUTE OF TECHNOLOGY BANGALORE SOUTH CAMPUS 1 ST INTERNAL ASSESMENT TEST (SCEME AND SOLUTIONS)

P.E.S. INSTITUTE OF TECHNOLOGY BANGALORE SOUTH CAMPUS 1 ST INTERNAL ASSESMENT TEST (SCEME AND SOLUTIONS) FACULTY: Ms. Saritha P.E.S. INSTITUTE OF TECHNOLOGY BANGALORE SOUTH CAMPUS 1 ST INTERNAL ASSESMENT TEST (SCEME AND SOLUTIONS) SUBJECT / CODE: Programming in C and Data Structures- 15PCD13 What is token?

More information

Fundamental of Programming (C)

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

More information

C - Basic Introduction

C - Basic Introduction C - Basic Introduction C is a general-purpose high level language that was originally developed by Dennis Ritchie for the UNIX operating system. It was first implemented on the Digital Equipment Corporation

More information

DEPARTMENT OF MATHS, MJ COLLEGE

DEPARTMENT OF MATHS, MJ COLLEGE T. Y. B.Sc. Mathematics MTH- 356 (A) : Programming in C Unit 1 : Basic Concepts Syllabus : Introduction, Character set, C token, Keywords, Constants, Variables, Data types, Symbolic constants, Over flow,

More information

Preview from Notesale.co.uk Page 6 of 52

Preview from Notesale.co.uk Page 6 of 52 Binary System: The information, which it is stored or manipulated by the computer memory it will be done in binary mode. RAM: This is also called as real memory, physical memory or simply memory. In order

More information

PESIT Bangalore South Campus Hosur road, 1km before Electronic City, Bengaluru -100 Department of Basic Science and Humanities

PESIT Bangalore South Campus Hosur road, 1km before Electronic City, Bengaluru -100 Department of Basic Science and Humanities INTERNAL ASSESSMENT TEST 1 SOLUTION PART 1 1 a Define algorithm. Write an algorithm to find sum and average of three numbers. 4 An Algorithm is a step by step procedure to solve a given problem in finite

More information

PART I. Part II Answer to all the questions 1. What is meant by a token? Name the token available in C++.

PART I.   Part II Answer to all the questions 1. What is meant by a token? Name the token available in C++. Unit - III CHAPTER - 9 INTRODUCTION TO C++ Choose the correct answer. PART I 1. Who developed C++? (a) Charles Babbage (b) Bjarne Stroustrup (c) Bill Gates (d) Sundar Pichai 2. What was the original name

More information

Reserved Words and Identifiers

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

More information

INTRODUCTION 1 AND REVIEW

INTRODUCTION 1 AND REVIEW INTRODUTION 1 AND REVIEW hapter SYS-ED/ OMPUTER EDUATION TEHNIQUES, IN. Programming: Advanced Objectives You will learn: Program structure. Program statements. Datatypes. Pointers. Arrays. Structures.

More information

Programming Fundamentals (CS 302 ) Dr. Ihsan Ullah. Lecturer Department of Computer Science & IT University of Balochistan

Programming Fundamentals (CS 302 ) Dr. Ihsan Ullah. Lecturer Department of Computer Science & IT University of Balochistan Programming Fundamentals (CS 302 ) Dr. Ihsan Ullah Lecturer Department of Computer Science & IT University of Balochistan 1 Outline p Introduction p Program development p C language and beginning with

More information

C OVERVIEW. C Overview. Goals speed portability allow access to features of the architecture speed

C OVERVIEW. C Overview. Goals speed portability allow access to features of the architecture speed C Overview C OVERVIEW Goals speed portability allow access to features of the architecture speed C fast executables allows high-level structure without losing access to machine features many popular languages

More information

A Fast Review of C Essentials Part I

A Fast Review of C Essentials Part I A Fast Review of C Essentials Part I Structural Programming by Z. Cihan TAYSI Outline Program development C Essentials Functions Variables & constants Names Formatting Comments Preprocessor Data types

More information

Fundamental Data Types. CSE 130: Introduction to Programming in C Stony Brook University

Fundamental Data Types. CSE 130: Introduction to Programming in C Stony Brook University Fundamental Data Types CSE 130: Introduction to Programming in C Stony Brook University Program Organization in C The C System C consists of several parts: The C language The preprocessor The compiler

More information

C OVERVIEW BASIC C PROGRAM STRUCTURE. C Overview. Basic C Program Structure

C OVERVIEW BASIC C PROGRAM STRUCTURE. C Overview. Basic C Program Structure C Overview Basic C Program Structure C OVERVIEW BASIC C PROGRAM STRUCTURE Goals The function main( )is found in every C program and is where every C program begins speed execution portability C uses braces

More information

Java Notes. 10th ICSE. Saravanan Ganesh

Java Notes. 10th ICSE. Saravanan Ganesh Java Notes 10th ICSE Saravanan Ganesh 13 Java Character Set Character set is a set of valid characters that a language can recognise A character represents any letter, digit or any other sign Java uses

More information

P.E.S. INSTITUTE OF TECHNOLOGY BANGALORE SOUTH CAMPUS DEPARTMENT OF SCIENCE AND HUMANITIES EVEN SEMESTER FEB 2017

P.E.S. INSTITUTE OF TECHNOLOGY BANGALORE SOUTH CAMPUS DEPARTMENT OF SCIENCE AND HUMANITIES EVEN SEMESTER FEB 2017 P.E.S. INSTITUTE OF TECHNOLOGY BANGALORE SOUTH CAMPUS DEPARTMENT OF SCIENCE AND HUMANITIES ST INTERNAL ASSESMENT TEST (SCEME AND SOLUTIONS) EVEN SEMESTER FEB 07 FACULTY: Dr.J Surya Prasad/Ms. Saritha/Mr.

More information

Unit-II Programming and Problem Solving (BE1/4 CSE-2)

Unit-II Programming and Problem Solving (BE1/4 CSE-2) Unit-II Programming and Problem Solving (BE1/4 CSE-2) Problem Solving: Algorithm: It is a part of the plan for the computer program. An algorithm is an effective procedure for solving a problem in a finite

More information

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

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

More information

Character Set. The character set of C represents alphabet, digit or any symbol used to represent information. Digits 0, 1, 2, 3, 9

Character Set. The character set of C represents alphabet, digit or any symbol used to represent information. Digits 0, 1, 2, 3, 9 Character Set The character set of C represents alphabet, digit or any symbol used to represent information. Types Uppercase Alphabets Lowercase Alphabets Character Set A, B, C, Y, Z a, b, c, y, z Digits

More information

Presented By : Gaurav Juneja

Presented By : Gaurav Juneja Presented By : Gaurav Juneja Introduction C is a general purpose language which is very closely associated with UNIX for which it was developed in Bell Laboratories. Most of the programs of UNIX are written

More information

Introduction to C Language

Introduction to C Language Introduction to C Language Instructor: Professor I. Charles Ume ME 6405 Introduction to Mechatronics Fall 2006 Instructor: Professor Charles Ume Introduction to C Language History of C Language In 1972,

More information

UNIT IV 2 MARKS. ( Word to PDF Converter - Unregistered ) FUNDAMENTALS OF COMPUTING & COMPUTER PROGRAMMING

UNIT IV 2 MARKS. ( Word to PDF Converter - Unregistered )   FUNDAMENTALS OF COMPUTING & COMPUTER PROGRAMMING ( Word to PDF Converter - Unregistered ) http://www.word-to-pdf-converter.net FUNDAMENTALS OF COMPUTING & COMPUTER PROGRAMMING INTRODUCTION TO C UNIT IV Overview of C Constants, Variables and Data Types

More information

Introduction to C programming. By Avani M. Sakhapara Asst Professor, IT Dept, KJSCE

Introduction to C programming. By Avani M. Sakhapara Asst Professor, IT Dept, KJSCE Introduction to C programming By Avani M. Sakhapara Asst Professor, IT Dept, KJSCE Classification of Software Computer Software System Software Application Software Growth of Programming Languages History

More information

Objectives. Chapter 2: Basic Elements of C++ Introduction. Objectives (cont d.) A C++ Program (cont d.) A C++ Program

Objectives. Chapter 2: Basic Elements of C++ Introduction. Objectives (cont d.) A C++ Program (cont d.) A C++ Program Objectives Chapter 2: Basic Elements of C++ 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

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

Chapter 2: Basic Elements of C++ Objectives. Objectives (cont d.) A C++ Program. Introduction

Chapter 2: Basic Elements of C++ Objectives. Objectives (cont d.) A C++ Program. Introduction Chapter 2: Basic Elements of C++ C++ Programming: From Problem Analysis to Program Design, Fifth Edition 1 Objectives In this chapter, you will: Become familiar with functions, special symbols, and identifiers

More information

Basic Elements of C. Staff Incharge: S.Sasirekha

Basic Elements of C. Staff Incharge: S.Sasirekha Basic Elements of C Staff Incharge: S.Sasirekha Basic Elements of C Character Set Identifiers & Keywords Constants Variables Data Types Declaration Expressions & Statements C Character Set Letters Uppercase

More information

Computer System and programming in C

Computer System and programming in C 1 Basic Data Types Integral Types Integers are stored in various sizes. They can be signed or unsigned. Example Suppose an integer is represented by a byte (8 bits). Leftmost bit is sign bit. If the sign

More information

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

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

More information

C Language, Token, Keywords, Constant, variable

C Language, Token, Keywords, Constant, variable C Language, Token, Keywords, Constant, variable A language written by Brian Kernighan and Dennis Ritchie. This was to be the language that UNIX was written in to become the first "portable" language. C

More information

Chapter 1 & 2 Introduction to C Language

Chapter 1 & 2 Introduction to C Language 1 Chapter 1 & 2 Introduction to C Language Copyright 2007 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 1 & 2 - Introduction to C Language 2 Outline 1.1 The History

More information

The component base of C language. Nguyễn Dũng Faculty of IT Hue College of Science

The component base of C language. Nguyễn Dũng Faculty of IT Hue College of Science The component base of C language Nguyễn Dũng Faculty of IT Hue College of Science Content A brief history of C Standard of C Characteristics of C The C compilation model Character set and keyword Data

More information

C: How to Program. Week /Mar/05

C: How to Program. Week /Mar/05 1 C: How to Program Week 2 2007/Mar/05 Chapter 2 - Introduction to C Programming 2 Outline 2.1 Introduction 2.2 A Simple C Program: Printing a Line of Text 2.3 Another Simple C Program: Adding Two Integers

More information

Fundamentals of Programming

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

More information

ANSI C Programming Simple Programs

ANSI C Programming Simple Programs ANSI C Programming Simple Programs /* This program computes the distance between two points */ #include #include #include main() { /* Declare and initialize variables */ double

More information

SEQUENTIAL STRUCTURE. Erkut ERDEM Hacettepe University October 2010

SEQUENTIAL STRUCTURE. Erkut ERDEM Hacettepe University October 2010 SEQUENTIAL STRUCTURE Erkut ERDEM Hacettepe University October 2010 History of C C Developed by by Denis M. Ritchie at AT&T Bell Labs from two previous programming languages, BCPL and B Used to develop

More information

6.096 Introduction to C++ January (IAP) 2009

6.096 Introduction to C++ January (IAP) 2009 MIT OpenCourseWare http://ocw.mit.edu 6.096 Introduction to C++ January (IAP) 2009 For information about citing these materials or our Terms of Use, visit: http://ocw.mit.edu/terms. Welcome to 6.096 Lecture

More information

IECD Institute for Entrepreneurship and Career Development Bharathidasan University, Tiruchirappalli 23.

IECD Institute for Entrepreneurship and Career Development Bharathidasan University, Tiruchirappalli 23. Subject code - CCP01 Chapt Chapter 1 INTRODUCTION TO C 1. A group of software developed for certain purpose are referred as ---- a. Program b. Variable c. Software d. Data 2. Software is classified into

More information

Differentiate Between Keywords and Identifiers

Differentiate Between Keywords and Identifiers History of C? Why we use C programming language Martin Richards developed a high-level computer language called BCPL in the year 1967. The intention was to develop a language for writing an operating system(os)

More information

Chapter 2 - Introduction to C Programming

Chapter 2 - Introduction to C Programming Chapter 2 - Introduction to C Programming 2 Outline 2.1 Introduction 2.2 A Simple C Program: Printing a Line of Text 2.3 Another Simple C Program: Adding Two Integers 2.4 Memory Concepts 2.5 Arithmetic

More information

Intro to Computer Programming (ICP) Rab Nawaz Jadoon

Intro to Computer Programming (ICP) Rab Nawaz Jadoon Intro to Computer Programming (ICP) Rab Nawaz Jadoon DCS COMSATS Institute of Information Technology Assistant Professor COMSATS IIT, Abbottabad Pakistan Introduction to Computer Programming (ICP) What

More information

ADARSH VIDYA KENDRA NAGERCOIL COMPUTER SCIENCE. Grade: IX C++ PROGRAMMING. Department of Computer Science 1

ADARSH VIDYA KENDRA NAGERCOIL COMPUTER SCIENCE. Grade: IX C++ PROGRAMMING. Department of Computer Science 1 NAGERCOIL COMPUTER SCIENCE Grade: IX C++ PROGRAMMING 1 C++ 1. Object Oriented Programming OOP is Object Oriented Programming. It was developed to overcome the flaws of the procedural approach to programming.

More information

BCA-105 C Language What is C? History of C

BCA-105 C Language What is C? History of C C Language What is C? C is a programming language developed at AT & T s Bell Laboratories of USA in 1972. It was designed and written by a man named Dennis Ritchie. C seems so popular is because it is

More information

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

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

More information

CSC 1107: Structured Programming

CSC 1107: Structured Programming CSC 1107: Structured Programming J. Kizito Makerere University e-mail: www: materials: e-learning environment: office: alt. office: jkizito@cis.mak.ac.ug http://serval.ug/~jona http://serval.ug/~jona/materials/csc1107

More information

4.1. Structured program development Overview of C language

4.1. Structured program development Overview of C language 4.1. Structured program development 4.2. Data types 4.3. Operators 4.4. Expressions 4.5. Control flow 4.6. Arrays and Pointers 4.7. Functions 4.8. Input output statements 4.9. storage classes. UNIT IV

More information

Operators and Expressions:

Operators and Expressions: Operators and Expressions: Operators and expression using numeric and relational operators, mixed operands, type conversion, logical operators, bit operations, assignment operator, operator precedence

More information

Department of Computer Applications

Department of Computer Applications Sheikh Ul Alam Memorial Degree College Mr. Ovass Shafi. (Assistant Professor) C Language An Overview (History of C) C programming languages is the only programming language which falls under the category

More information

COMPUTER SCIENCE HIGHER SECONDARY FIRST YEAR. VOLUME II - CHAPTER 10 PROBLEM SOLVING TECHNIQUES AND C PROGRAMMING 1,2,3 & 5 MARKS

COMPUTER SCIENCE HIGHER SECONDARY FIRST YEAR.  VOLUME II - CHAPTER 10 PROBLEM SOLVING TECHNIQUES AND C PROGRAMMING 1,2,3 & 5 MARKS COMPUTER SCIENCE HIGHER SECONDARY FIRST YEAR VOLUME II - CHAPTER 10 PROBLEM SOLVING TECHNIQUES AND C PROGRAMMING 1,2,3 & 5 MARKS S.LAWRENCE CHRISTOPHER, M.C.A., B.Ed., LECTURER IN COMPUTER SCIENCE PONDICHERRY

More information

Course Outline Introduction to C-Programming

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

More information

JAVA Programming Fundamentals

JAVA Programming Fundamentals Chapter 4 JAVA Programming Fundamentals By: Deepak Bhinde PGT Comp.Sc. JAVA character set Character set is a set of valid characters that a language can recognize. It may be any letter, digit or any symbol

More information

DECLARATIONS. Character Set, Keywords, Identifiers, Constants, Variables. Designed by Parul Khurana, LIECA.

DECLARATIONS. Character Set, Keywords, Identifiers, Constants, Variables. Designed by Parul Khurana, LIECA. DECLARATIONS Character Set, Keywords, Identifiers, Constants, Variables Character Set C uses the uppercase letters A to Z. C uses the lowercase letters a to z. C uses digits 0 to 9. C uses certain Special

More information

KARMAYOGI ENGINEERING COLLEGE, Shelve Pandharpur

KARMAYOGI ENGINEERING COLLEGE, Shelve Pandharpur KARMAYOGI ENGINEERING COLLEGE, Shelve Pandharpur Bachelor of Engineering First Year Subject Name: Computer Programming Objective: 1. This course is designed to provide a brief study of the C programming

More information

EC 413 Computer Organization

EC 413 Computer Organization EC 413 Computer Organization C/C++ Language Review Prof. Michel A. Kinsy Programming Languages There are many programming languages available: Pascal, C, C++, Java, Ada, Perl and Python All of these languages

More information

THE FUNDAMENTAL DATA TYPES

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

More information

Unit 3. Operators. School of Science and Technology INTRODUCTION

Unit 3. Operators. School of Science and Technology INTRODUCTION INTRODUCTION Operators Unit 3 In the previous units (unit 1 and 2) you have learned about the basics of computer programming, different data types, constants, keywords and basic structure of a C program.

More information

C Fundamentals & Formatted Input/Output. adopted from KNK C Programming : A Modern Approach

C Fundamentals & Formatted Input/Output. adopted from KNK C Programming : A Modern Approach C Fundamentals & Formatted Input/Output adopted from KNK C Programming : A Modern Approach C Fundamentals 2 Program: Printing a Pun The file name doesn t matter, but the.c extension is often required.

More information

Programming and Data Structures

Programming and Data Structures Programming and Data Structures Teacher: Sudeshna Sarkar sudeshna@cse.iitkgp.ernet.in Department of Computer Science and Engineering Indian Institute of Technology Kharagpur #include int main()

More information

Basics of Programming

Basics of Programming Unit 2 Basics of Programming Problem Analysis When we are going to develop any solution to the problem, we must fully understand the nature of the problem and what we want the program to do. Without the

More information

C Language Part 1 Digital Computer Concept and Practice Copyright 2012 by Jaejin Lee

C Language Part 1 Digital Computer Concept and Practice Copyright 2012 by Jaejin Lee C Language Part 1 (Minor modifications by the instructor) References C for Python Programmers, by Carl Burch, 2011. http://www.toves.org/books/cpy/ The C Programming Language. 2nd ed., Kernighan, Brian,

More information

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

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

More information

BLM2031 Structured Programming. Zeyneb KURT

BLM2031 Structured Programming. Zeyneb KURT BLM2031 Structured Programming Zeyneb KURT 1 Contact Contact info office : D-219 e-mail zeynebkurt@gmail.com, zeyneb@ce.yildiz.edu.tr When to contact e-mail first, take an appointment What to expect help

More information

Mechatronics and Microcontrollers. Szilárd Aradi PhD Refresh of C

Mechatronics and Microcontrollers. Szilárd Aradi PhD Refresh of C Mechatronics and Microcontrollers Szilárd Aradi PhD Refresh of C About the C programming language The C programming language is developed by Dennis M Ritchie in the beginning of the 70s One of the most

More information

Number Systems, Scalar Types, and Input and Output

Number Systems, Scalar Types, and Input and Output Number Systems, Scalar Types, and Input and Output Outline: Binary, Octal, Hexadecimal, and Decimal Numbers Character Set Comments Declaration Data Types and Constants Integral Data Types Floating-Point

More information

A First Program - Greeting.cpp

A First Program - Greeting.cpp C++ Basics A First Program - Greeting.cpp Preprocessor directives Function named main() indicates start of program // Program: Display greetings #include using namespace std; int main() { cout

More information

CSc 10200! Introduction to Computing. Lecture 2-3 Edgardo Molina Fall 2013 City College of New York

CSc 10200! Introduction to Computing. Lecture 2-3 Edgardo Molina Fall 2013 City College of New York CSc 10200! Introduction to Computing Lecture 2-3 Edgardo Molina Fall 2013 City College of New York 1 C++ for Engineers and Scientists Third Edition Chapter 2 Problem Solving Using C++ 2 Objectives In this

More information

Basic Types and Formatted I/O

Basic Types and Formatted I/O Basic Types and Formatted I/O C Variables Names (1) Variable Names Names may contain letters, digits and underscores The first character must be a letter or an underscore. the underscore can be used but

More information

Lesson 3 Introduction to Programming in C

Lesson 3 Introduction to Programming in C jgromero@inf.uc3m.es Lesson 3 Introduction to Programming in C Programming Grade in Industrial Technology Engineering This work is licensed under a Creative Commons Reconocimiento-NoComercial-CompartirIgual

More information

Variables Data types Variable I/O. C introduction. Variables. Variables 1 / 14

Variables Data types Variable I/O. C introduction. Variables. Variables 1 / 14 C introduction Variables Variables 1 / 14 Contents Variables Data types Variable I/O Variables 2 / 14 Usage Declaration: t y p e i d e n t i f i e r ; Assignment: i d e n t i f i e r = v a l u e ; Definition

More information

Operators. Java operators are classified into three categories:

Operators. Java operators are classified into three categories: Operators Operators are symbols that perform arithmetic and logical operations on operands and provide a meaningful result. Operands are data values (variables or constants) which are involved in operations.

More information

1.1 Introduction to C Language. Department of CSE

1.1 Introduction to C Language. Department of CSE 1.1 Introduction to C Language 1 Department of CSE Objectives To understand the structure of a C-Language Program To write a minimal C program To introduce the include preprocessor command To be able to

More information

Guide for The C Programming Language Chapter 1. Q1. Explain the structure of a C program Answer: Structure of the C program is shown below:

Guide for The C Programming Language Chapter 1. Q1. Explain the structure of a C program Answer: Structure of the C program is shown below: Q1. Explain the structure of a C program Structure of the C program is shown below: Preprocessor Directives Global Declarations Int main (void) Local Declarations Statements Other functions as required

More information

Computer programming & Data Structures Unit I Introduction to Computers

Computer programming & Data Structures Unit I Introduction to Computers Computer programming & Data Structures Unit I Introduction to Computers (1) What are system software and application software? What are the differences between them? A piece of software is a program or

More information

EL2310 Scientific Programming

EL2310 Scientific Programming (yaseminb@kth.se) Overview Overview Roots of C Getting started with C Closer look at Hello World Programming Environment Discussion Basic Datatypes and printf Schedule Introduction to C - main part of

More information

PESIT Bangalore South Campus Hosur Road (1km before Electronic City), Bengaluru Department of Basic Science and Humanities

PESIT Bangalore South Campus Hosur Road (1km before Electronic City), Bengaluru Department of Basic Science and Humanities SOLUTION OF CONTINUOUS INTERNAL EVALUATION TEST -1 Date : 27-02 2018 Marks:60 Subject & Code : Programming in C and Data Structures- 17PCD23 Name of faculty : Dr. J Surya Prasad/Mr. Naushad Basha Saudagar

More information

Objectives. In this chapter, you will:

Objectives. In this chapter, you will: 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 arithmetic expressions Learn about

More information

Unit 1: Introduction to C Language. Saurabh Khatri Lecturer Department of Computer Technology VIT, Pune

Unit 1: Introduction to C Language. Saurabh Khatri Lecturer Department of Computer Technology VIT, Pune Unit 1: Introduction to C Language Saurabh Khatri Lecturer Department of Computer Technology VIT, Pune Introduction to C Language The C programming language was designed by Dennis Ritchie at Bell Laboratories

More information

C++ character set Letters:- A-Z, a-z Digits:- 0 to 9 Special Symbols:- space + - / ( ) [ ] =! = < >, $ # ; :? & White Spaces:- Blank Space, Horizontal

C++ character set Letters:- A-Z, a-z Digits:- 0 to 9 Special Symbols:- space + - / ( ) [ ] =! = < >, $ # ; :? & White Spaces:- Blank Space, Horizontal TOKENS C++ character set Letters:- A-Z, a-z Digits:- 0 to 9 Special Symbols:- space + - / ( ) [ ] =! = < >, $ # ; :? & White Spaces:- Blank Space, Horizontal Tab, Vertical tab, Carriage Return. Other Characters:-

More information

Programming in C++ 4. The lexical basis of C++

Programming in C++ 4. The lexical basis of C++ Programming in C++ 4. The lexical basis of C++! Characters and tokens! Permissible characters! Comments & white spaces! Identifiers! Keywords! Constants! Operators! Summary 1 Characters and tokens A C++

More information

C Programming Multiple. Choice

C Programming Multiple. Choice C Programming Multiple Choice Questions 1.) Developer of C language is. a.) Dennis Richie c.) Bill Gates b.) Ken Thompson d.) Peter Norton 2.) C language developed in. a.) 1970 c.) 1976 b.) 1972 d.) 1980

More information

C++ Programming: From Problem Analysis to Program Design, Third Edition

C++ Programming: From Problem Analysis to Program Design, Third Edition C++ Programming: From Problem Analysis to Program Design, Third Edition Chapter 2: Basic Elements of C++ Objectives (continued) Become familiar with the use of increment and decrement operators Examine

More information

Operators and Expressions in C & C++ Mahesh Jangid Assistant Professor Manipal University, Jaipur

Operators and Expressions in C & C++ Mahesh Jangid Assistant Professor Manipal University, Jaipur Operators and Expressions in C & C++ Mahesh Jangid Assistant Professor Manipal University, Jaipur Operators and Expressions 8/24/2012 Dept of CS&E 2 Arithmetic operators Relational operators Logical operators

More information

Introduction to C Programming. Chih-Wei Tang ( 唐之瑋 ) Department of Communication Engineering National Central University JhongLi, Taiwan

Introduction to C Programming. Chih-Wei Tang ( 唐之瑋 ) Department of Communication Engineering National Central University JhongLi, Taiwan Introduction to C Programming Chih-Wei Tang ( 唐之瑋 ) Department of Communication Engineering National Central University JhongLi, Taiwan Outline Printing texts Adding 2 integers Comparing 2 integers C.E.,

More information

Muntaser Abulafi Yacoub Sabatin Omar Qaraeen. C Data Types

Muntaser Abulafi Yacoub Sabatin Omar Qaraeen. C Data Types Programming Fundamentals for Engineers 0702113 5. Basic Data Types Muntaser Abulafi Yacoub Sabatin Omar Qaraeen 1 2 C Data Types Variable definition C has a concept of 'data types' which are used to define

More information

MODULE 1: INTRODUCTION TO C LANGUAGE. Questions and Answers on Pseudocode solution to a problem

MODULE 1: INTRODUCTION TO C LANGUAGE. Questions and Answers on Pseudocode solution to a problem MODULE 1: INTRODUCTION TO C LANGUAGE Questions and Answers on Pseudocode solution to a problem Q.1 What is algorithm? Write the characteristics of an algorithm. Give an example for algorithm. Definition

More information

Lecture 02 C FUNDAMENTALS

Lecture 02 C FUNDAMENTALS Lecture 02 C FUNDAMENTALS 1 Keywords C Fundamentals auto double int struct break else long switch case enum register typedef char extern return union const float short unsigned continue for signed void

More information

About Codefrux While the current trends around the world are based on the internet, mobile and its applications, we try to make the most out of it. As for us, we are a well established IT professionals

More information

Types, Operators and Expressions

Types, Operators and Expressions Types, Operators and Expressions EECS 2031 18 September 2017 1 Variable Names (2.1) l Combinations of letters, numbers, and underscore character ( _ ) that do not start with a number; are not a keyword.

More information

Programming for Engineers Introduction to C

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

More information

Types, Operators and Expressions

Types, Operators and Expressions Types, Operators and Expressions CSE 2031 Fall 2011 9/11/2011 5:24 PM 1 Variable Names (2.1) Combinations of letters, numbers, and underscore character ( _ ) that do not start with a number; are not a

More information

UNIT-2 Introduction to C++

UNIT-2 Introduction to C++ UNIT-2 Introduction to C++ C++ CHARACTER SET Character set is asset of valid characters that a language can recognize. A character can represents any letter, digit, or any other sign. Following are some

More information

UNIT 3 OPERATORS. [Marks- 12]

UNIT 3 OPERATORS. [Marks- 12] 1 UNIT 3 OPERATORS [Marks- 12] SYLLABUS 2 INTRODUCTION C supports a rich set of operators such as +, -, *,,

More information