CPU Unit Wise IMP Questions Answers for GTU

Size: px
Start display at page:

Download "CPU Unit Wise IMP Questions Answers for GTU"

Transcription

1 CPU Unit Wise IMP Questions Answers for GTU UNIT: 1 (Introduction to Computer Programming) 1) Draw block diagram of computer system. Explain each part of it. The computer performs basically five major operations of functions irrespective of their size and make. These are 1) it accepts data or instruction by way of input, 2) it stores data, 3) it can process data as required by the user, 4) it gives results in the form of output, and 5) it controls all operations inside a computer. We discuss below each of these operations. 1. Input: this is the process of entering data and programs into the computer system.e.g Keyboard,Mouse,Digital Pen.etc.. 2. Control Unit (CU): The process of input, output, processing and storage is performed under the supervision of a unit called 'Control Unit'. It decides when to start receiving data, when to stop it, where to store data, etc. It takes care of step -by-step processing of all operations in side the computer. 3. Memory Unit: Computer is used to store data and instructions. 4. Arithmetic Logic Unit (ALU): The major operations performed by the ALU are addition, subtraction, multiplication, division, logic and comparison. 5. Output: This is the process of producing results from the data for getting useful information. E.g Monitor,Speaker.

2 The ALU and the CU of a computer system are jointly known as the central processing unit (CPU). You may call CPU as the brain of any computer system. 2) What is Software and Hardware? Explain different types of Software. Hardware:- The term hardware describes the physical parts of your computer which you can physically touch or see such as your monitor, case, disk drives, microprocessor and other physical parts. Software:- The term software describes the programs that run on your system. This includes your computer operating system and other computer programs which run. Software is written in a computer language (such as Basic, C, Java, or others) by programmers.. Writing these text files and converting them to computer readable files is the way operating systems and most application programs are created. System software and application programs are the two main types of computer software. Application software Unlike system software, an application program (often just called an application or app) performs a particular function for the user. Examples (among many possibilities) include browsers, clients, word processors and spreadsheets. System software System software is a type of computer program that is designed to run a computer s hardware and application programs. If we think of the computer system as a layered model, the system software is the interface between the hardware and user applications. The operating system (OS) is the best-known example of system software. The OS manages all the other programs in a computer. 3) Explain various symbols used in Flowchart and draw the flowchart for finding Factorial of a number given by user. Flowcharts use special shapes to represent different types of actions or steps in a process. Lines and arrows show the sequence of the steps, and the relationships among them. These are known as flowchart symbols.

3 The connector symbol connects separate elements across one page. It s usually used within complex charts. The process symbol represents a process, action, or function. It s the most widelyused symbol in flowcharting. The decision symbol indicates a question to be answered usually yes/no or true/false. The flowchart path may splinter into different branches depending on the answer. The data symbol (also called the input/output symbol) represents data that is available for input or output. It may also represent resources used or generated. The paper tape symbol also represents input/output, but is outdated and no longer in common usage. Another symbol used to represent data is the circle shape. Finding Factorial of a number given by user.

4 4) Define algorithm and explain different symbols used in flowchart. Step by step procedure designed to perform an operation. Algorithms have a definite beginning and a definite end, and a finite number of steps. An algorithm produces the same output information given the same input information. For flowchart symbol please refer Q.3 Ans. 5) Explain different type of operators used in C language with their precedence and associativity. An operator is a symbol that tells the compiler to perform specific mathematical or logical manipulations. C language is rich in built-in operators and provides the following types of operators: Arithmetic Operators Relational Operators Logical Operators Bitwise Operators Assignment Operators Increment/Decrement Operators Special Operator Conditional Operator Arithmetic Operators C supports all the basic arithmetic operators. The following table shows all the basic arithmetic operators.

5 Operator Description + adds two operands - subtract second operands from first \* multiply two operand / divide numerator by denumerator % remainder of division ++ Increment operator increases integer value by one -- Decrement operator decreases integer value by one Relational Operators The following table shows all relation operators supported by C. Operator Description == Check if two operand are equal!= Check if two operand are not equal. > Check if operand on the left is greater than operand on the right < Check operand on the left is smaller than right operand >= check left operand is greater than or equal to right operand <= Check if operand on left is smaller than or equal to right operand Logical Operators C language supports following 3 logical operators. Suppose a=1 and b=0, Operator Description Example && Logical AND (a && b) is false Logical OR (a b) is true! Logical NOT (!a) is false Bitwise Operators

6 Bitwise operators perform manipulations of data at bit level. These operators also perform shifting of bitsfrom right to left. Bitwise operators are not applied to float or double. Operator & Description Bitwise AND Bitwise OR ^ Bitwise exclusive OR << left shift >> right shift Now lets see truth table for bitwise &, and ^ A B a & b a b a ^ b The bitwise shift operators shifts the bit value. The left operand specifies the value to be shifted and the right operand specifies the number of positions that the bits in the value are to be shifted. Both operands have the same precedence. Example : a = b= 2 a << b = a >> b = Assignment operators Assignment operators supported by C language are as follows. Operator Description Example = assigns values from right side operands to left side operand a=b += adds right operand to the left operand and assign the result to left a+=b is same as a=a+b

7 -= subtracts right operand from the left operand and assign the result to left operand *= mutiply left operand with the right operand and assign the result to left operand /= divides left operand with the right operand and assign the result to left operand %= calculate modulus using two operands and assign the result to left operand a-=b is same as a=ab a*=b is same as a=a*b a/=b is same as a=a/b a%=b is same as a=a%b Conditional Operator It is also known as ternary operator and used to evaluate conditional expression. epr1? expr2 : expr3 If epr1 Condition is true? Then value expr2 : Otherwise value expr3 Special Operators Operator Description Example Sizeof Returns the size of an variable sizeof(x) return size of the variable x & Returns the address of an variable &x ; return address of the variable x * Pointer to a variable *x ; will be pointer to a variable x Increment/Decrement Operators Increment operators are used to increase the value of the variable by one and decrement operators are used to decrease the value of the variable by one in C programs. Syntax: Increment operator: ++var_name; (or) var_name++; Decrement operator: -var_name; (or) var_name -; Example: Increment operator : ++ i ; i ++ ; Decrement operator : i ; i ; C operators in order of precedence (highest to lowest). Their associativity indicates in what order operators of equal precedence in an expression are applied. Operator Description Associativity

8 ( ) [ ]. -> ! ~ (type) * & sizeof Parentheses (function call) (see Note 1) Brackets (array subscript) Member selection via object name Member selection via pointer Postfix increment/decrement (see Note 2) Prefix increment/decrement Unary plus/minus Logical negation/bitwise complement Cast (convert value to temporary value of type) Dereference Address (of operand) Determine size in bytes on this implementation left-to-right right-to-left * / % Multiplication/division/modulus left-to-right + - Addition/subtraction left-to-right << >> Bitwise shift left, Bitwise shift right left-to-right < <= > >= Relational less than/less than or equal to Relational greater than/greater than or equal to left-to-right ==!= Relational is equal to/is not equal to left-to-right & Bitwise AND left-to-right ^ Bitwise exclusive OR left-to-right Bitwise inclusive OR left-to-right && Logical AND left-to-right Logical OR left-to-right? : Ternary conditional right-to-left = += -= *= /= %= &= ^= = <<= >>= Assignment Addition/subtraction assignment Multiplication/division assignment Modulus/bitwise AND assignment Bitwise exclusive/inclusive OR assignment Bitwise shift left/right assignment right-to-left, Comma (separate expressions) left-to-right Note 1:Parentheses are also used to group sub-expressions to force a different precedence; such parenthetical expressions can be nested and are evaluated from inner to outer. Note 2:Postfix increment/decrement have high precedence, but the actual increment or decrement of the operand is delayed (to be accomplished sometime before the statement completes execution). So in the statement y = x * z++; the current value of z is used to evaluate the expression (i.e., z++ evaluates to z) and z only incremented after all else is done.

9 UNIT : 2 Fundamentals of C 1) State the syntax of Switch-case statement. Explain it with appropriate example. Decision making are needed when, the program encounters the situation to choose a particular statement among many statements. If a programmer has to choose one block of statement among many alternatives, nested if...else can be used but, this makes programming logic complex. This type of problem can be handled in C programming using switch statement. Syntax of switch...case switch (n) { case constant1: code/s to be executed if n equals to constant1; break; case constant2: code/s to be executed if n equals to constant2; break;... default: code/s to be executed if n doesn't match to any cases; The value of n is either an integer or a character in above syntax. If the value of n matches constant in case, the relevant codes are executed and control moves out of the switch statement. If the ndoesn't matches any of the constant in case, then the default codes are executed and control moves out of switch statement.

10 Example of switch...case statement Write a program that asks user an arithmetic operator('+','-','*' or '/') and two operands and perform the corresponding calculation on the operands. /* C program to demonstrate the working of switch...case statement */ /* C Program to create a simple calculator for addition, subtraction, multiplication and division */ # include <stdio.h> int main() { char o; float num1,num2; printf("select an operator either + or - or * or / \n"); scanf("%c",&o); printf("enter two operands: "); scanf("%f%f",&num1,&num2); switch(o) { case '+': printf("%.1f + %.1f = %.1f",num1, num2, num1+num2); break; case '-': printf("%.1f - %.1f = %.1f",num1, num2, num1-num2); break;

11 case '*': printf("%.1f * %.1f = %.1f",num1, num2, num1*num2); break; case '/': printf("%.1f / %.1f = %.1f",num1, num2, num1/num2); break; default: /* If operator is other than +, -, * or /, error message is shown */ printf("error! operator is not correct"); break; return 0; Output Enter operator either + or - or * or / * Enter two operands: * 4.5 = 10.3 The break statement at the end of each case cause switch statement to exit. If break statement is not used, all statements below that case statement are also executed. 2) What do you understand by looping? Explain different types of loops in C with example. You may encounter situations, when a block of code needs to be executed several number of times. In general, statements are executed sequentially: The first statement in a function is executed first, followed by the second, and so on. Programming languages provide various control structures that allow for more complicated execution paths. A loop statement allows us to execute a statement or group of statements multiple times. Given below is the general form of a loop statement in most of the programming languages

12 C programming language provides the following types of loops to handle looping requirements. while loop: A while loop in C programming repeatedly executes a target statement as long as a given condition is true. Syntax The syntax of a while loop in C programming language is while(condition) { statement(s); Here, statement(s) may be a single statement or a block of statements. The condition may be any expression, and true is any nonzero value. The loop iterates while the condition is true. When the condition becomes false, the program control passes to the line immediately following the loop. Flow Diagram

13 Here, the key point to note is that a while loop might not execute at all. When the condition is tested and the result is false, the loop body will be skipped and the first statement after the while loop will be executed. Example #include <stdio.h> int main () { /* local variable definition */ int a = 10; /* while loop execution */ while( a < 20 ) { printf("value of a: %d\n", a); a++; return 0; When the above code is compiled and executed, it produces the following result value of a: 10 value of a: 11 value of a: 12 value of a: 13

14 value of a: 14 value of a: 15 value of a: 16 value of a: 17 value of a: 18 value of a: 19 for loop: A for loop is a repetition control structure that allows you to efficiently write a loop that needs to execute a specific number of times. Syntax The syntax of a for loop in C programming language is for ( init; condition; increment ) { statement(s); Here is the flow of control in a 'for' loop The init step is executed first, and only once. This step allows you to declare and initialize any loop control variables. You are not required to put a statement here, as long as a semicolon appears. Next, the condition is evaluated. If it is true, the body of the loop is executed. If it is false, the body of the loop does not execute and the flow of control jumps to the next statement just after the 'for' loop. After the body of the 'for' loop executes, the flow of control jumps back up to the increment statement. This statement allows you to update any loop control variables. This statement can be left blank, as long as a semicolon appears after the condition. The condition is now evaluated again. If it is true, the loop executes and the process repeats itself (body of loop, then increment step, and then again condition). After the condition becomes false, the 'for' loop terminates.

15 Flow Diagram: Example #include <stdio.h> int main () { int a; /* for loop execution */ for( a = 10; a < 20; a = a + 1 ){ printf("value of a: %d\n", a); return 0; When the above code is compiled and executed, it produces the following result value of a: 10 value of a: 11 value of a: 12 value of a: 13 value of a: 14 value of a: 15 value of a: 16 value of a: 17

16 value of a: 18 value of a: 19 do...while loop: Unlike for and while loops, which test the loop condition at the top of the loop, the do...while loop in C programming checks its condition at the bottom of the loop. A do...while loop is similar to a while loop, except the fact that it is guaranteed to execute at least one time. Syntax The syntax of a do...while loop in C programming language is do { statement(s); while( condition ); Notice that the conditional expression appears at the end of the loop, so the statement(s) in the loop executes once before the condition is tested. If the condition is true, the flow of control jumps back up to do, and the statement(s) in the loop executes again. This process repeats until the given condition becomes false. Flow Diagram Example #include <stdio.h> int main () { /* local variable definition */ int a = 10; /* do loop execution */

17 do { printf("value of a: %d\n", a); a = a + 1; while( a < 20 ); return 0; When the above code is compiled and executed, it produces the following result value of a: 10 value of a: 11 value of a: 12 value of a: 13 value of a: 14 value of a: 15 value of a: 16 value of a: 17 value of a: 18 value of a: 19 3) What is array? Explain single and multidimensional with examples. Arrays a kind of data structure that can store a fixed-size sequential collection of elements of the same type. An array is used to store a collection of data, but it is often more useful to think of an array as a collection of variables of the same type. Instead of declaring individual variables, such as number0, number1,..., and number99, you declare one array variable such as numbers and use numbers[0], numbers[1], and..., numbers[99] to represent individual variables. A specific element in an array is accessed by an index. All arrays consist of contiguous memory locations. The lowest address corresponds to the first element and the highest address to the last element. Single-dimensional Arrays: Declaring Arrays: To declare an array in C, a programmer specifies the type of the elements and the number of elements required by an array as follows type arrayname [ arraysize ];

18 This is called a single-dimensional array. The arraysize must be an integer constant greater than zero and type can be any valid C data type. For example, to declare a 10-element array calledbalance of type double, use this statement double balance[10]; Here balance is a variable array which is sufficient to hold up to 10 double numbers. Initializing Arrays: You can initialize an array in C either one by one or using a single statement as follows double balance[5] = {1000.0, 2.0, 3.4, 7.0, 50.0; The number of values between braces { cannot be larger than the number of elements that we declare for the array between square brackets [ ]. If you omit the size of the array, an array just big enough to hold the initialization is created. Therefore, if you write double balance[] = {1000.0, 2.0, 3.4, 7.0, 50.0; You will create exactly the same array as you did in the previous example. Following is an example to assign a single element of the array balance[4] = 50.0; The above statement assigns the 5 th element in the array with a value of All arrays have 0 as the index of their first element which is also called the base index and the last index of an array will be total size of the array minus 1. Shown below is the pictorial representation of the array we discussed above Accessing Array Elements: An element is accessed by indexing the array name. This is done by placing the index of the element within square brackets after the name of the array. For example double salary = balance[9]; The above statement will take the 10 th element from the array and assign the value to salary variable. The following example Shows how to use all the three above mentioned concepts viz. declaration, assignment, and accessing arrays #include <stdio.h> int main () { int n[ 10 ]; /* n is an array of 10 integers */ int i,j; /* initialize elements of array n to 0 */ for ( i = 0; i < 10; i++ ) { n[ i ] = i + 100; /* set element at location i to i */

19 /* output each array element's value */ for (j = 0; j < 10; j++ ) { printf("element[%d] = %d\n", j, n[j] ); return 0; When the above code is compiled and executed, it produces the following result Element[0] = 100 Element[1] = 101 Element[2] = 102 Element[3] = 103 Element[4] = 104 Element[5] = 105 Element[6] = 106 Element[7] = 107 Element[8] = 108 Element[9] = 109 Multidimensional Arrays: C programming language allows multidimensional arrays. Here is the general form of a multidimensional array declaration type name[size1][size2]...[sizen]; For example, the following declaration creates a three dimensional integer array int threedim[5][10][4]; Two-dimensional Arrays: The simplest form of multidimensional array is the two-dimensional array. A two-dimensional array is, in essence, a list of one-dimensional arrays. To declare a two-dimensional integer array of size [x][y], you would write something as follows type arrayname [ x ][ y ]; Where type can be any valid C data type and arrayname will be a valid C identifier. A twodimensional array can be considered as a table which will have x number of rows and y number of columns. A two-dimensional array a, which contains three rows and four columns can be shown as follows

20 Thus, every element in the array a is identified by an element name of the form a[ i ][ j ], where 'a' is the name of the array, and 'i' and 'j' are the subscripts that uniquely identify each element in 'a'. Initializing Two-Dimensional Arrays Multidimensional arrays may be initialized by specifying bracketed values for each row. Following is an array with 3 rows and each row has 4 columns. int a[3][4] = { {0, 1, 2, 3, /* initializers for row indexed by 0 */ {4, 5, 6, 7, /* initializers for row indexed by 1 */ {8, 9, 10, 11 /* initializers for row indexed by 2 */ ; The nested braces, which indicate the intended row, are optional. The following initialization is equivalent to the previous example int a[3][4] = {0,1,2,3,4,5,6,7,8,9,10,11; Accessing Two-Dimensional Array Elements An element in a two-dimensional array is accessed by using the subscripts, i.e., row index and column index of the array. For example int val = a[2][3]; The above statement will take the 4th element from the 3rd row of the array. You can verify it in the above figure. Let us check the following program where we have used a nested loop to handle a two-dimensional array #include <stdio.h> int main () { /* an array with 5 rows and 2 columns*/ int a[5][2] = { {0,0, {1,2, {2,4, {3,6,{4,8; int i, j; /* output each array element's value */ for ( i = 0; i < 5; i++ ) { for ( j = 0; j < 2; j++ ) { printf("a[%d][%d] = %d\n", i,j, a[i][j] ); return 0; When the above code is compiled and executed, it produces the following result a[0][0]: 0 a[0][1]: 0 a[1][0]: 1

21 a[1][1]: 2 a[2][0]: 2 a[2][1]: 4 a[3][0]: 3 a[3][1]: 6 a[4][0]: 4 a[4][1]: 8 As explained above, you can have arrays with any number of dimensions, although it is likely that most of the arrays you create will be of one or two dimensions. 4) Explain break and continue with example. Loop control statements change execution from its normal sequence. When execution leaves a scope, all automatic objects that were created in that scope are destroyed. C supports the following control statements. break statement: The break statement in C programming has the following two usages When a break statement is encountered inside a loop, the loop is immediately terminated and the program control resumes at the next statement following the loop. It can be used to terminate a case in the switchstatement (covered in the next chapter). If you are using nested loops, the break statement will stop the execution of the innermost loop and start executing the next line of code after the block. Syntax The syntax for a break statement in C is as follows break; Flow Diagram

22 Example #include <stdio.h> int main () { /* local variable definition */ int a = 10; /* while loop execution */ while( a < 20 ) { printf("value of a: %d\n", a); a++; if( a > 15) { /* terminate the loop using break statement */ break; return 0; When the above code is compiled and executed, it produces the following result value of a: 10 value of a: 11 value of a: 12 value of a: 13 value of a: 14 value of a: 15 continue statement: The continue statement in C programming works somewhat like the break statement. Instead of forcing termination, it forces the next iteration of the loop to take place, skipping any code in between. For the for loop, continue statement causes the conditional test and increment portions of the loop to execute. For the while anddo...while loops, continue statement causes the program control to pass to the conditional tests. Syntax The syntax for a continue statement in C is as follows continue; Flow Diagram

23 Example #include <stdio.h> int main () { /* local variable definition */ int a = 10; /* do loop execution */ do { if( a == 15) { /* skip the iteration */ a = a + 1; continue; printf("value of a: %d\n", a); a++; while( a < 20 ); return 0; When the above code is compiled and executed, it produces the following result value of a: 10 value of a: 11 value of a: 12

24 value of a: 13 value of a: 14 value of a: 16 value of a: 17 value of a: 18 value of a: 19 5) Explain if...else if..ladder with flowchart. Suppose we need to specify multiple conditions then we need to use multiple if statements like this void main ( ) { int num = 10 ; if ( num > 0 ) printf ("\n Number is Positive"); if ( num < 0 ) printf ("\n Number is Negative"); if ( num == 0 ) printf ("\n Number is Zero"); which is not a right or feasible way to write program. Instead of this above syntax we use ifelse-if statement. Consider the Following Program void main ( ) { int num = 10 ; if ( num > 0 ) printf ("\n Number is Positive"); else if ( num < 0 ) printf ("\n Number is Negative"); else printf ("\n Number is Zero"); Explanation : In the above program firstly condition is tested i.e number is checked with zero. If it is greater than zero then only first if statement will be executed and after the execution of if statement control will be outside the complete if-else statement. else if ( num < 0 ) printf ("\n Number is Negative"); Suppose in first if condition is false then the second condition will be tested i.e if number is not positive then and then only it is tested for the negative. else

25 printf ("\n Number is Zero"); and if number is neither positive nor negative then it will be considered as zero. Which is faster and feasible way for Writing If? Point Example 1 Example 2 No of If Statements 3 2 No of times Condition 3 1 Tested (Positive No.) No of times Condition 3 2 Tested (Negative No.) No of times Condition Tested (Zero No.) 3 2 6) What is type conversion? Explain implicit type conversion and explicit type conversion with example. Type Casting and Type Conversions : Because C is statically-typed at compile time, after a variable is declared, it cannot be declared again or used to store values of another type unless that type is convertible to the variable's type. For example, there is no conversion from an integer to any arbitrary string. Therefore, after you declare i as an integer, you cannot assign the string "Hello" to it, as is shown in the following code.

26 int i; i = "Hello"; // Error: "Cannot implicitly convert type 'string' to 'int'" However, you might sometimes need to copy a value into a variable or method parameter of another type. For example, you might have an integer variable that you need to pass to a method whose parameter is typed as double. Or you might need to assign a class variable to a variable of an interface type. These kinds of operations are called type conversions. In C#, you can perform the following kinds of conversions: Implicit conversions: No special syntax is required because the conversion is type safe and no data will be lost. Examples include conversions from smaller to larger integral types, and conversions from derived classes to base classes. Explicit conversions (casts): Explicit conversions require a cast operator. Casting is required when information might be lost in the conversion, or when the conversion might not succeed for other reasons. Typical examples include numeric conversion to a type that has less precision or a smaller range, and conversion of a base-class instance to a derived class. Implicit Conversions: For built-in numeric types, an implicit conversion can be made when the value to be stored can fit into the variable without being truncated or rounded off. For example, a variable of type long (8 byte integer) can store any value that an int (4 bytes on a 32-bit computer) can store. In the following example, the compiler implicitly converts the value on the right to a type long before assigning it to bignum. C // Implicit conversion. num long can // hold any value an int can hold, and more! int num = ; long bignum = num; For a complete list of all implicit numeric conversions, see For reference types, an implicit conversion always exists from a class to any one of its direct or indirect base classes or interfaces. No special syntax is necessary because a derived class always contains all the members of a base class. Derived d = new Derived(); Base b = d; // Always OK. Explicit Conversions: However, if a conversion cannot be made without a risk of losing information, the compiler requires that you perform an explicit conversion, which is called a cast. A cast is a way of explicitly informing the compiler that you intend to make the conversion and that you are aware that data loss might occur. To perform a cast, specify the type that you are casting to in parentheses in front of the value or variable to be converted. The following program casts a doubleto an int. The program will not compile without the cast. class Test { void Main()

27 { double x = ; int a; // Cast double to int. a = (int)x; PRINTF(a); // Output: ) Define (1) Token (2) Identifier (3) Constant (4) Type casting (5) Storage class (6) Scope and life time of variable. (1) Token: A C program consists of various tokens and a token is either a keyword, an identifier, a constant, a string literal, or a symbol. For example, the following C statement consists of five tokens printf("hello, World! \n"); The individual tokens are printf ( "Hello, World! \n" ) ; (2) Identifier: A C identifier is a name used to identify a variable, function, or any other user-defined item. An identifier starts with a letter A to Z, a to z, or an underscore '_' followed by zero or more letters, underscores, and digits (0 to 9). C does not allow punctuation characters such $, and % within identifiers. C is a casesensitive programming language. Thus, Manpower and manpower are two different identifiers in C. Here are some examples of acceptable identifiers mohd zara abc move_name a_123 myname50 _temp j a23b9 retval (3) Constant: Constants refer to fixed values that the program may not alter during its execution. These fixed values are also called literals. Constants can be of any of the basic data types like an integer constant, a floating constant, a character constant, or a string literal. There are enumeration constants as well. Constants are treated just like regular variables except that their values cannot be modified after their definition.

28 (4) Type casting: Refer Que. 6. (5) Storage class: A storage class defines the scope (visibility) and life-time of variables and/or functions within a C Program. They precede the type that they modify. We have four different storage classes in a C program auto register static extern (6) Scope and life time of variable: Life Time Life time of any variable is the time for which the particular variable outlives in memory during running of the program. Scope The scope of any variable is actually a subset of life time. A variable may be in the memory but may not be accessible though. So, the area of our program where we can actually access our entity (variable in this case) is the scope of that variable. The scope of any variable can be broadly categorized into three categories : Global scope : When variable is defined outside all functions. It is then available to all the functions of the program and all the blocks program contains. Local scope : When variable is defined inside a function or a block, then it is locally accessible within the block and hence it is a local variable. Function scope : When variable is passed as formal arguments, it is said to have function scope. 8) Explain operator precedence and associativity. Precedence of operators: If more than one operators are involved in an expression then, C language has predefined rule of priority of operators. This rule of priority of operators is called operator precedence. In C, precedence of arithmetic operators(*,%,/,+,-) is higher than relational operators(==,!=,>,<,>=,<=) and precedence of relational operator is higher than logical operators(&&, and!). Suppose an expression: (a>b+c&&d) This expression is equivalent to: ((a>(b+c))&&d) i.e, (b+c) executes first then, (a>(b+c)) executes

29 then, (a>(b+c))&&d) executes Associativity of operators: Associativity indicates in which order two operators of same precedence(pri ority) executes. Let us suppose an expression: a==b!=c Here, operators == and!= have same precedence. The associativity of both == and!= is left to right, i.e, the expression in left is executed first and execution take pale towards right. Thus, a==b!=cequivalent to : (a==b)!=c The table below shows all the operators in C with precedence and associativity. Note: Precedence of operators decreases from top to bottom in the given table. Summary of C operators with precedence and associativity Operator Meaning of operator Associativity () [] ->.! ~ & * sizeof (type) * / % + - << >> Functional call Array element reference Indirect member selection Direct member selection Logical negation Bitwise(1 's) complement Unary plus Unary minus Increment Decrement Dereference Operator(Address) Pointer reference Returns the size of an object Type cast(conversion) Multiply Divide Remainder Binary plus(addition) Binary minus(subtraction) Left shift Right shift Left to right Right to left Left to right Left to right Left to right

30 Summary of C operators with precedence and associativity Operator Meaning of operator Associativity < <= > >= ==!= Less than Less than or equal Greater than Greater than or equal Equal to Not equal to Left to right Left to right & Bitwise AND Left to right ^ Bitwise exclusive OR Left to right Bitwise OR Left to right && Logical AND Left to right Logical OR Left to right?: Conditional Operator Left to right = *= /= %= -= &= ^= = <<= >>= Simple assignment Assign product Assign quotient Assign remainder Assign sum Assign difference Assign bitwise AND Assign bitwise XOR Assign bitwise OR Assign left shift Assign right shift Right to left, Separator of expressions Left to right

31 UNIT: 3 ( Control Structure in C) 1) Explain the multiple (ladder) if-else with syntax and proper example. OR Explain if...else...if ladder of C with neat diagram and a brief program code. If statement can be followed by an optional else if...else statement, which is very useful to test various conditions using single if...else if statement. When using if...else if..else statements, there are few points to keep in mind An if can have zero or one else's and it must come after any else if's. An if can have zero to many else if's and they must come before the else. Once an else if succeeds, none of the remaining else if's or else's will be tested. Syntax The syntax of an if...else if...else statement in C programming language is if(boolean_expression 1) { /* Executes when the boolean expression 1 is true */ else if( boolean_expression 2) { /* Executes when the boolean expression 2 is true */ else if( boolean_expression 3) { /* Executes when the boolean expression 3 is true */ else { /* executes when the none of the above condition is true */ Example #include <stdio.h> #include<conio.h> int main () { int a = 100; if( a == 10 ) { printf("value of a is 10\n" ); else if( a == 20 ) { printf("value of a is 20\n" ); else if( a == 30 ) { printf("value of a is 30\n" ); else {

32 printf("none of the values is matching\n" ); printf("exact value of a is: %d\n", a ); return 0; Output: None of the values is matching Exact value of a is: 100 2) Which among the following is a unconditional control structure. a) goto b) for c) do-while d) if-else a)goto 3) Write a C Program to check whether the given number is prime or not. #include<stdio.h> #include<conio.h> int main() { int num,i,count=0; printf("enter a number: "); scanf("%d",&num); for(i=2;i<=num/2;i++){ if(num%i==0){ count++; break; if(count==0 && num!= 1) printf("%d is a prime number",num); else printf("%d is not a prime number",num); return 0; output: Enter a number: 5 5 is a prime number

33 4) What is looping? Explain different types of loops in C and compare them. Show how to sum 1 to 10 using each of these loops. A loop statement allows us to execute a statement or group of statements multiple times. The general form of a loop statement is shown below. a)while loop : A while loop in C programming repeatedly executes a target statement as long as a given condition is true. Syntax The syntax of a while loop in C programming language is while(condition) { statement(s); Here, statement(s) may be a single statement or a block of statements. The condition may be any expression, and true is any nonzero value. The loop iterates while the condition is true. When the condition becomes false, the program control passes to the line immediately following the loop. Flow Diagram

34 Here, the key point to note is that a while loop might not execute at all. When the condition is tested and the result is false, the loop body will be skipped and the first statement after the while loop will be executed. Example #include <stdio.h> int main () { int a = 10; while( a < 20 ) { printf("value of a: %d\n", a); a++; return 0; Output: value of a: 10 value of a: 11 value of a: 12 value of a: 13 value of a: 14 value of a: 15 value of a: 16 value of a: 17 value of a: 18 value of a: 19

35 b)do while loop A do...while loop is similar to a while loop, except the fact that it is guaranteed to execute at least one time. Syntax The syntax of a do...while loop in C programming language is do { statement(s); while( condition ); The conditional expression appears at the end of the loop, so the statement(s) in the loop executes once before the condition is tested. If the condition is true, the flow of control jumps back up to do, and the statement(s) in the loop executes again. This process repeats until the given condition becomes false. Flow Diagram Example #include <stdio.h> int main () { int a = 10; do { printf("value of a: %d\n", a); a = a + 1; while( a < 20 ); return 0;

36 Output: value of a: 10 value of a: 11 value of a: 12 value of a: 13 value of a: 14 value of a: 15 value of a: 16 value of a: 17 value of a: 18 value of a: 19 c) for loop A for loop is a repetition control structure that allows you to efficiently write a loop that needs to execute a specific number of times. Syntax The syntax of a for loop in C programming language is for ( init; condition; increment ) { statement(s); Here is the flow of control in a 'for' loop The init step is executed first, and only once. This step allows you to declare and initialize any loop control variables. You are not required to put a statement here, as long as a semicolon appears. Next, the condition is evaluated. If it is true, the body of the loop is executed. If it is false, the body of the loop does not execute and the flow of control jumps to the next statement just after the 'for' loop. After the body of the 'for' loop executes, the flow of control jumps back up to the increment statement. This statement allows you to update any loop control variables. This statement can be left blank, as long as a semicolon appears after the condition. The condition is now evaluated again. If it is true, the loop executes and the process repeats itself (body of loop, then increment step, and then again condition). After the condition becomes false, the 'for' loop terminates. Flow Diagram

37 Example #include <stdio.h> int main () { int a; for( a = 10; a < 20; a = a + 1 ){ printf("value of a: %d\n", a); return 0; Output: value of a: 10 value of a: 11 value of a: 12 value of a: 13 value of a: 14 value of a: 15 value of a: 16 value of a: 17 value of a: 18 value of a: 19

38 C Program to sum 1 to 10 Numbers Using For Loop #include<stdio.h> #include<conio.h> void main() { int i = 1,sum=0; for (i = 1; i <= 10; i++) { sum=sum+i; printf("%d", sum); getch(); Using While Loop #include<stdio.h> #include<conio.h> void main() { int i = 1,sum=0; while (i <= 10) { sum=sum+i; i++; printf("%d", sum); getch(); Using Do While Loop #include<stdio.h> #include<conio.h> void main() { int i = 1,sum=0; do { sum=sum+i; i++; while (i <= 10); printf("%d",sum); getch();

39 UNIT:4 (Array and String) 1) What is array? What are the advantages to use array? Explain single and multi-dimensional array with example. Arrays a kind of data structure that can store a fixed-size sequential collection of elements of the same type. An array is used to store a collection of data, but it is often more useful to think of an array as a collection of variables of the same type. Instead of declaring individual variables, such as number0, number1,..., and number99, you declare one array variable such as numbers and use numbers[0], numbers[1], and..., numbers[99] to represent individual variables. A specific element in an array is accessed by an index. All arrays consist of contiguous memory locations. The lowest address corresponds to the first element and the highest address to the last element. Advantages: 1. It is used to represent multiple data items of same type by using only single name. 2. It can be used to implement other data structures like linked lists, stacks, queues, trees, graphs etc. 3. 2D arrays are used to represent matrices. Single Dimensional Array: The declaration form of one-dimensional array is Data_type array_name [size]; The following declares an array called numbers to hold 5 integers and sets the first and last elements. C arrays are always indexed from 0. So the first integer in numbers array is numbers[0] and the last is numbers[4]. int numbers [5]; numbers [0] = 1; // set first element numbers [4] = 5; // set last element This array contains 5 elements. Any one of these elements may be referred to by giving the name of the array followed by the position number of the particular element in square brackets ([]). The first element in every array is the zeroth element.thus, the first element of

40 array numbers is referred to as numbers[ 0 ], the second element of array numbers is referred to as numbers[ 1 ], the fifth element of array numbers is referred to as numbers[ 4 ], and, in general, the n-th element of array numbers is referred to as numbers[ n - 1 ]. Example: #include<stdio.h> #include<conio.h> void main() { int arr[10]; int i,sum=0,avg=0; clrscr(); for(i=0;i<10;i++) { scanf("%d",&arr[i]); sum = sum + arr[i]; printf("\n Sum of array elements = %d",sum); avg = sum/10; printf("\n Average = %d",avg); getch(); Multi dimensional array: The simplest form of multidimensional array is the two-dimensional array. A two-dimensional array is, in essen arrays. To declare a two-dimensional integer array of size [x][y], you would write something as follows type arrayname [ x ][ y ]; Where type can be any valid C data type and arrayname will be a valid C identifier. A two-dimensional array ca which will have x number of rows and y number of columns. A two-dimensional array a, which contains three r be shown as follows

41 Thus, every element in the array a is identified by an element name of the forma[ i ][ j ], where 'a' is the name o are the subscripts that uniquely identify each element in 'a'. Example: #include<stdio.h> int main() { int m,n,c,d,first[10][10],second[10][10],sum[10][10]; printf("enter the number of rows and columns of matrix\n"); scanf("%d%d", &m, &n); printf("enter the elements of first matrix\n"); for (c = 0; c < m; c++) for (d = 0; d < n; d++) scanf("%d", &first[c][d]); printf("enter the elements of second matrix\n"); for (c = 0; c < m; c++) for (d = 0 ; d < n; d++) scanf("%d", &second[c][d]); printf("sum of entered matrices:-\n"); for (c = 0; c < m; c++) { for (d = 0 ; d < n; d++) { sum[c][d] = first[c][d] + second[c][d]; printf("%d\t", sum[c][d]); printf("\n"); return 0; 2) Describe various string handling operation using sample C codes. (1)strlen():

42 strlen() function returns the length of the string. strlen() function returns integer value. Syntax: strlen(s) Example: #include <stdio.h> #include <string.h> int main(){ char a[20]="program"; char b[20]={'p','r','o','g','r','a','m','\0'; char c[20]; printf("enter string: "); gets(c); printf("length of string a=%d \n",strlen(a)); //calculates the length of string before null charcter. printf("length of string b=%d \n",strlen(b)); printf("length of string c=%d \n",strlen(c)); return 0; (2)strcpy(): strcpy() function is used to copy one string to another. The Destination_String should be a variable and Source_String can either be a string constant or a variable. Syntax: strcpy(destination_string,source_string); Example: #include <stdio.h> #include <string.h> int main(){ char a[10],b[10]; printf("enter string: "); gets(a); strcpy(b,a); //Content of string a is copied to string b. printf("copied string: "); puts(b); return 0; (3)strcat(): strcat() is used to concatenate two strings. The Destination_String should be a variable and Source_String can either be a string constant or a variable.

43 Syntax: strcat(destination_string, Source_String); Example: #include <stdio.h> #include <string.h> int main(){ char str1[]="this is ", str2[]="programiz.com"; strcat(str1,str2); //concatenates str1 and str2 and resultant string is stored in str1. puts(str1); puts(str2); return 0; (4)strcmp(): strcmp() function is use two compare two strings. strcmp() function does a case sensitive comparison between two strings. The Destination_String and Source_String can either be a string constant or a variable. Syntax: int strcmp(string1, string2); This function returns integer value after comparison. Value returned is 0 if two strings are equal. If the first string is alphabetically greater than the second string then, it returns a positive value. If the first string is alphabetically less than the second string then, it returns a negative value Example: #include <stdio.h> #include <string.h> int main(){ char str1[30],str2[30]; printf("enter first string: "); gets(str1); printf("enter second string: "); gets(str2); if(strcmp(str1,str2)==0) printf("both strings are equal");

44 else printf("strings are unequal"); return 0; (5)strcmpi(): strcmpi() function is use two compare two strings. strcmp() function does a case insensitive comparison between two strings. The Destination_String and Source_String can either be a string constant or a variable. Syntax: int strcmpi(string1, string2); This function returns integer value after comparison. Example: char *string1 = Learn C Online ; char *string2 = LEARN C ONLINE ; int ret ret=strcmpi(string1, string2); printf("%d",ret); (6) strlwr(): In C programming, strlwr() function converts all the uppercase characters in that string to lowercase characters. The resultant from strlwr() is stored in the same string. Syntax: strlwr(string_name); Example: #include <stdio.h> #include <string.h> int main(){ char str1[]="lower Case"; puts(strlwr(str1)); //converts to lowercase and displays it. return 0; (7) strupr():

45 In C programming, strupr() function converts all the lowercase characters in that string to uppercase characters. The resultant from strupr() is stored in the same string. Syntax: strupr(string_name); Example: #include <stdio.h> #include <string.h> int main(){ char str1[]="upper Case"; puts(strupr(str1)); //Converts to uppercase and displays it. return 0; 3) What is a string? How string is stored in C? Give the various functions with their use for string processing. A string in C is merely an array of characters. The length of a string is determined by a terminating null character: '\0'. So, a string with the contents, say, "abc" has four characters: 'a', 'b', 'c', and the terminatingnull character. The terminating null character has the value zero. A string stored is COMPUTER,which is having only 8 characters,but actually 9 characters are Stored because of NULL character at the end. Char name[20]; This line declares an array name of characters of size 20.we can store any string up to maximum lengh 19. String is basically an array of characters,so we can initialize the string by using the method of initializing the method of initializing the single dimensional array as shown below. Char name[] = { C, O, M, P, U, T, E, R ; OR Char name[] = COMPUTER ; When the string is written in double quotes,the NULL character is not required,it is automatically taken. (1)strlen(): strlen() function returns the length of the string. strlen() function returns integer value. Syntax: strlen(s)

46 Example: #include <stdio.h> #include <string.h> int main(){ char a[20]="program"; char b[20]={'p','r','o','g','r','a','m','\0'; char c[20]; printf("enter string: "); gets(c); printf("length of string a=%d \n",strlen(a)); //calculates the length of string before null charcter. printf("length of string b=%d \n",strlen(b)); printf("length of string c=%d \n",strlen(c)); return 0; (2)strcpy(): strcpy() function is used to copy one string to another. The Destination_String should be a variable and Source_String can either be a string constant or a variable. Syntax: strcpy(destination_string,source_string); Example: #include <stdio.h> #include <string.h> int main(){ char a[10],b[10]; printf("enter string: "); gets(a); strcpy(b,a); //Content of string a is copied to string b. printf("copied string: "); puts(b); return 0; (3)strcat(): strcat() is used to concatenate two strings. The Destination_String should be a variable and Source_String can either be a string constant or a variable.

47 Syntax: strcat(destination_string, Source_String); Example: #include <stdio.h> #include <string.h> int main(){ char str1[]="this is ", str2[]="programiz.com"; strcat(str1,str2); //concatenates str1 and str2 and resultant string is stored in str1. puts(str1); puts(str2); return 0; (4)strcmp(): strcmp() function is use two compare two strings. strcmp() function does a case sensitive comparison between two strings. The Destination_String and Source_String can either be a string constant or a variable. Syntax: int strcmp(string1, string2); This function returns integer value after comparison. Value returned is 0 if two strings are equal. If the first string is alphabetically greater than the second string then, it returns a positive value. If the first string is alphabetically less than the second string then, it returns a negative value Example: #include <stdio.h> #include <string.h> int main(){ char str1[30],str2[30]; printf("enter first string: "); gets(str1); printf("enter second string: "); gets(str2); if(strcmp(str1,str2)==0) printf("both strings are equal"); else printf("strings are unequal"); return 0;

48 (5)strcmpi(): strcmpi() function is use two compare two strings. strcmp() function does a case insensitive comparison between two strings. The Destination_String and Source_String can either be a string constant or a variable. Syntax: int strcmpi(string1, string2); This function returns integer value after comparison. Example: char *string1 = Learn C Online ; char *string2 = LEARN C ONLINE ; int ret ret=strcmpi(string1, string2); printf("%d",ret); (6) strlwr(): In C programming, strlwr() function converts all the uppercase characters in that string to lowercase characters. The resultant from strlwr() is stored in the same string. Syntax: strlwr(string_name); Example: #include <stdio.h> #include <string.h> int main(){ char str1[]="lower Case"; puts(strlwr(str1)); //converts to lowercase and displays it. return 0; (7) strupr(): In C programming, strupr() function converts all the lowercase characters in that string to uppercase characters. The resultant from strupr() is stored in the same string. Syntax: strupr(string_name);

49 Example: #include <stdio.h> #include <string.h> int main(){ char str1[]="upper Case"; puts(strupr(str1)); //Converts to uppercase and displays it. return 0;

50 UNIT:5 (Function) 1) What is function? Explain Pass by value and Pass by reference. Give one-one example of User Defined Function and Library Function. Function is a group of statements as a single unit known by some name which is performing some well defined task. The syntax for function declaration is : type function_name(argument(s)); Here,type specifies the type of value returned,function_name specifies name of user defined function, and argument(s) specifies the arguments supplied to the function as comma separated list of variables. The declaration of function is terminated by semicolon (;) symbol. When a function is called from other function,the parameters can be passed in two ways. Call By Value Call By Reference In call By Value,argument values are passed to the function,the contents of actual parameters are copied into the formal parameters.the function called function can not change the values of variables which are passed.even if a function tries to change the values of passed parameters,those changes will occur in formal parameters,not in actual parameters. Example: #include<conio.h> void sum(int a, int b); main() { int i,j; clrscr(); printf( Give two integer numbers\n ); scanf( %d %d,&i,&j); sum(i,j); void sum(int a,int b) { int c; c=a+b; printf( Sum of %d and %d=%d\n,a,b,c); Output:

51 Give two integer numbers 2 3 Sum of 2 and 3=5 Void sum(int a,int b); declaration says that sum function takes two values but does not return any value.program shows function with arguments but no return value. Sum(I,j); indicates that function calls by value. In Call By Reference,as the name suggests,the reference of the parameter i.e. address(pointer) is passed to the function and not the value.because pointer is passed,the called function can change the content of the actual parameter passed.call by reference is used whenever we want to change the value of local variables declared in one function to be changed by other function. #include<conio.h> int add(int*,int*); //Function prototyping void main() { int num1, num2, result; clrscr(); //This inbuilt function clears the screen /*Accept the numbers from the user*/ printf("\nenter the two number: "); scanf("%d %d", &num1, &num2); /* Pass the value of num1 and num2 as parameter to function add. The value returned is stored in the variable result */ result = add(&num1, &num2); printf("\naddition of %d and %d is %d", num1, num2, result); getch(); /*Defining the function add()*/ int add(int *no1, int *no2) { int res; res = *no1 + *no2;

52 return res; 2) Write short note on Categories of Functions. Following are thetype in functions: Function with no arguments and no return value Function with no arguments and return value Function with arguments but no return value Function with arguments and return value. Let's take an example to find whether a number is prime or not using above 4 categories of user defined functions. Function with no arguments and no return value. /*C program to check whether a number entered by user is prime or not using function with no arguments and no return value*/ #include <stdio.h> void prime(); int main(){ prime(); //No argument is passed to prime(). return 0; void prime(){ /* There is no return value to calling function main(). Hence, return type of prime() is void */ int num,i,flag=0; printf("enter positive integer enter to check:\n"); scanf("%d",&num); for(i=2;i<=num/2;++i){ if(num%i==0){ flag=1; if (flag==1) printf("%d is not prime",num); else printf("%d is prime",num); Function prime() is used for asking user a input, check for whether it is prime of not and display it accordingly. No argument is passed and returned form prime() function. Function with no arguments but return value /*C program to check whether a number entered by user is prime or not using function with no arguments but having return value */

53 #include <stdio.h> int input(); int main(){ int num,i,flag = 0; num=input(); /* No argument is passed to input() */ for(i=2; i<=num/2; ++i){ if(num%i==0){ flag = 1; break; if(flag == 1) printf("%d is not prime",num); else printf("%d is prime", num); return 0; int input(){ /* Integer value is returned from input() to calling function */ int n; printf("enter positive integer to check:\n"); scanf("%d",&n); return n; There is no argument passed to input() function But, the value of n is returned from input() tomain() function. Function with arguments and no return value /*Program to check whether a number entered by user is prime or not using function with arguments and no return value */ #include <stdio.h> void check_display(int n); int main(){ int num; printf("enter positive enter to check:\n"); scanf("%d",&num); check_display(num); /* Argument num is passed to function. */ return 0; void check_display(int n){ /* There is no return value to calling function. Hence, return type of function is void. */ int i, flag = 0; for(i=2; i<=n/2; ++i){ if(n%i==0){

54 flag = 1; break; if(flag == 1) printf("%d is not prime",n); else printf("%d is prime", n); Here, check_display() function is used for check whether it is prime or not and display it accordingly. Here, argument is passed to user-defined function but, value is not returned from it to calling function. Function with argument and a return value /* Program to check whether a number entered by user is prime or not using function with argument and return value */ #include <stdio.h> int check(int n); int main(){ int num,num_check=0; printf("enter positive enter to check:\n"); scanf("%d",&num); num_check=check(num); /* Argument num is passed to check() function. */ if(num_check==1) printf("%d is not prime",num); else printf("%d is prime",num); return 0; int check(int n){ /* Integer value is returned from function check() */ int i; for(i=2;i<=n/2;++i){ if(n%i==0) return 1; return 0; Here, check() function is used for checking whether a number is prime or not. In this program, input from user is passed to function check() and integer value is returned from it. If input the number is prime, 0 is returned and if number is not prime, 1 is returned.

55 #include <stdio.h> #include <conio.h> max(int [],int); void main() { int a[]={10,5,45,12,19; int n=5,m; clrscr(); m=max(a,n); printf("\nmaximum NUMBER IS %d",m); getch(); max(int x[],int k) { int t,i; t=x[0]; for(i=1;i<k;i++) { if(x[i]>t) t=x[i]; return(t); Output : MAXIMUM NUMBER IS 45 3) What do you mean by recursive function? Explain with example. Recursion is the process of defining a problem (or the solution to a problem) in terms of (a simpler version of) itself. The standard recursive function for factorial is factorial=n*fact(n-1). factorial of number denoted by '!', means product of all non negative integers from 1 to number. example: 5!=5*4*3*2*1=120. Advantages: Easy solution for recursively defined problems. Complex programs can be easily written in less code. Disadvantages: Recursive code is difficult to understand and debug. Terminating condition is must,otherwise it will go in infinite loop. Execution speed decreases because of function call and return activity many times. #include<stdio.h>

56 int factorial(int); void main() { int num; printf("enter the number to calculate Factorial :"); scanf("%d",&num); printf("\nfactorial : %d", factorial (num)); int factorial (int i) { int f; if(i==1) return 1; else f = i* factorial (i-1); return f; 4 ) What is user-defined function? Explain Actual argument and formal argument User defined functions are created for doing some specific task in a program.the code is written as one unit having a name.as the size of program increases,it becomes difficult to understand,debug and maintain it.if we write the code in main() function only. When some portion of the code is repeated in the program and when there is a definite purpose of the code,we can write that part of the code as a function.so,use of function reduces the size and compklexity of the program.the code of the function is written only once in the program and called for any number of times from whenever required. Formal arguments are the arguments which are used in the definition of a function,while actual parameters are the arguments which are used while calling a function. Following example explains formal and actual arguments using user defined max function. #include<stdio.h> #include<conio.h> Int max(int x,int y) { If(x>y) Return x; else return y;

57 main() { int a=5,b=3; int ans; ans=max(a,b); printf( Maximum =%d\n,ans); In above program,x and y are formal parameters,while a and b are actual parameters.

58 UNIT 6 & 7 : (Pointer & structure) 1 ) What is pointer? How Pointer is initialized? How it is different to array? A pointer is a variable whose value is the address of another variable, i.e., direct address of the memory location. Like any variable or constant, you must declare a pointer before you can use it to store any variable address. The general form of a pointer variable declaration is: type *variable_name; Here, type is the pointer's base type; it must be a valid C data type and variable_name is the name of the pointer variable. Here, the asterisk is used to designate a variable as a pointer variable. Initialization of pointers: Pointer Initialization is the process of assigning address of a variable to pointer variable. First of all declare a Pointer Variable. Declare another Variable with Same Data Type as that of Pointer Variable. Now Initialize pointer by assigning the address of ordinary variable to pointer variable. For example: #include<stdio.h> void main() { int a; int *ptr; a = 10; ptr = &a; Difference between array and pointer: Array is a collection of variables; whereas pointer is a variable which stores the address of other variable. At the same time, we can have a pointer pointing to an array and an array of pointer variables. In arrays of C programming, name of the array always points to the first element of an array. 2 ) Write short note on Pointer. A pointer is a variable whose value is the address of another variable, i.e., direct address of the memory location. Like any variable or constant, you must declare a pointer before you can use it to store any variable address.

59 The general form of a pointer variable declaration is: type *variable_name; Here, type is the pointer's base type; it must be a valid C data type and variable_name is the name of the pointer variable. Here, the asterisk is used to designate a variable as a pointer. Initialization of a pointer variable can be done by by assigning the address of ordinary variable to pointer variable. e.g. int i =5; int *p; //declares p as pointer to integer p = &i; // p is assigned the address of int variable i. Advantages of pointer: It is the only way to express some computations. It produces compact and efficient code. It provides a very powerful tool. C uses pointers explicitly with Arrays,structures and functions. 3) What is structure? Define the structure and explain how to access the structure members. C arrays allow you to define type of variables that can hold several data items of the same kind but structure is another user defined data type available in C programming, which allows you to combine data items of different kinds. Declaration of structure: To define a structure, you must use the struct statement. The struct statement defines a new data type, with more than one member for your program. The format of the struct statement is this Struct books { char title[50]; char author[50] char subject[100]; int book_id[10]; book; Accessing a structure variable: To access any member of a structure, we use the member access operator (.). The member access operator is coded as a period between the structure variable name and the structure member that we wish to access. You would use struct keyword to define variables of structure type.

CP FAQS Q-1) Define flowchart and explain Various symbols of flowchart Q-2) Explain basic structure of c language Documentation section :

CP FAQS Q-1) Define flowchart and explain Various symbols of flowchart Q-2) Explain basic structure of c language Documentation section : CP FAQS Q-1) Define flowchart and explain Various symbols of flowchart ANS. Flowchart:- A diagrametic reperesentation of program is known as flowchart Symbols Q-2) Explain basic structure of c language

More information

To declare an array in C, a programmer specifies the type of the elements and the number of elements required by an array as follows

To declare an array in C, a programmer specifies the type of the elements and the number of elements required by an array as follows Unti 4: C Arrays Arrays a kind of data structure that can store a fixed-size sequential collection of elements of the same type An array is used to store a collection of data, but it is often more useful

More information

A complex expression to evaluate we need to reduce it to a series of simple expressions. E.g * 7 =>2+ 35 => 37. E.g.

A complex expression to evaluate we need to reduce it to a series of simple expressions. E.g * 7 =>2+ 35 => 37. E.g. 1.3a Expressions Expressions An Expression is a sequence of operands and operators that reduces to a single value. An operator is a syntactical token that requires an action be taken An operand is an object

More information

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

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

B.V. Patel Institute of Business Management, Computer & Information Technology, Uka Tarsadia University

B.V. Patel Institute of Business Management, Computer & Information Technology, Uka Tarsadia University Unit 1 Programming Language and Overview of C 1. State whether the following statements are true or false. a. Every line in a C program should end with a semicolon. b. In C language lowercase letters are

More information

Computers Programming Course 6. Iulian Năstac

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

More information

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

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

Computer Programming. C Array is a collection of data belongings to the same data type. data_type array_name[array_size];

Computer Programming. C Array is a collection of data belongings to the same data type. data_type array_name[array_size]; Arrays An array is a collection of two or more adjacent memory cells, called array elements. Array is derived data type that is used to represent collection of data items. C Array is a collection of data

More information

ARRAYS(II Unit Part II)

ARRAYS(II Unit Part II) ARRAYS(II Unit Part II) Array: An array is a collection of two or more adjacent cells of similar type. Each cell in an array is called as array element. Each array should be identified with a meaningful

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

Q 1. Attempt any TEN of the following:

Q 1. Attempt any TEN of the following: Subject Code: 17212 Model Answer Page No: 1 / 26 Important Instructions to examiners: 1) The answers should be examined by key words and not as word-to-word as given in the model answer scheme. 2) The

More information

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

A flow chart is a graphical or symbolic representation of a process. Q1. Define Algorithm with example? Answer:- A sequential solution of any program that written in human language, called algorithm. Algorithm is first step of the solution process, after the analysis of

More information

Part I Part 1 Expressions

Part I Part 1 Expressions Writing Program in C Expressions and Control Structures (Selection Statements and Loops) Jan Faigl Department of Computer Science Faculty of Electrical Engineering Czech Technical University in Prague

More information

Introduction. C provides two styles of flow control:

Introduction. C provides two styles of flow control: Introduction C provides two styles of flow control: Branching Looping Branching is deciding what actions to take and looping is deciding how many times to take a certain action. Branching constructs: if

More information

Writing Program in C Expressions and Control Structures (Selection Statements and Loops)

Writing Program in C Expressions and Control Structures (Selection Statements and Loops) Writing Program in C Expressions and Control Structures (Selection Statements and Loops) Jan Faigl Department of Computer Science Faculty of Electrical Engineering Czech Technical University in Prague

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

HISTORY OF C LANGUAGE. Facts about C. Why Use C?

HISTORY OF C LANGUAGE. Facts about C. Why Use C? 1 HISTORY OF C LANGUAGE C is a general-purpose, procedural, imperative computer programming language developed in 1972 by Dennis M. Ritchie at the Bell Telephone Laboratories to develop the UNIX operating

More information

Flow Control. CSC215 Lecture

Flow Control. CSC215 Lecture Flow Control CSC215 Lecture Outline Blocks and compound statements Conditional statements if - statement if-else - statement switch - statement? : opertator Nested conditional statements Repetitive statements

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

Model Viva Questions for Programming in C lab

Model Viva Questions for Programming in C lab Model Viva Questions for Programming in C lab Title of the Practical: Assignment to prepare general algorithms and flow chart. Q1: What is a flowchart? A1: A flowchart is a diagram that shows a continuous

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

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

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

More information

Expressions. Arithmetic expressions. Logical expressions. Assignment expression. n Variables and constants linked with operators

Expressions. Arithmetic expressions. Logical expressions. Assignment expression. n Variables and constants linked with operators Expressions 1 Expressions n Variables and constants linked with operators Arithmetic expressions n Uses arithmetic operators n Can evaluate to any value Logical expressions n Uses relational and logical

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

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

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

CSI33 Data Structures

CSI33 Data Structures Outline Department of Mathematics and Computer Science Bronx Community College October 24, 2018 Outline Outline 1 Chapter 8: A C++ Introduction For Python Programmers Expressions and Operator Precedence

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

M4.1-R3: PROGRAMMING AND PROBLEM SOLVING THROUGH C LANGUAGE

M4.1-R3: PROGRAMMING AND PROBLEM SOLVING THROUGH C LANGUAGE M4.1-R3: PROGRAMMING AND PROBLEM SOLVING THROUGH C LANGUAGE NOTE: 1. There are TWO PARTS in this Module/Paper. PART ONE contains FOUR questions and PART TWO contains FIVE questions. 2. PART ONE is to be

More information

Introduction. Following are the types of operators: Unary requires a single operand Binary requires two operands Ternary requires three operands

Introduction. Following are the types of operators: Unary requires a single operand Binary requires two operands Ternary requires three operands Introduction Operators are the symbols which operates on value or a variable. It tells the compiler to perform certain mathematical or logical manipulations. Can be of following categories: Unary requires

More information

Basic operators, Arithmetic, Relational, Bitwise, Logical, Assignment, Conditional operators. JAVA Standard Edition

Basic operators, Arithmetic, Relational, Bitwise, Logical, Assignment, Conditional operators. JAVA Standard Edition Basic operators, Arithmetic, Relational, Bitwise, Logical, Assignment, Conditional operators JAVA Standard Edition Java - Basic Operators Java provides a rich set of operators to manipulate variables.

More information

SECTION II: LANGUAGE BASICS

SECTION II: LANGUAGE BASICS Chapter 5 SECTION II: LANGUAGE BASICS Operators Chapter 04: Basic Fundamentals demonstrated declaring and initializing variables. This chapter depicts how to do something with them, using operators. Operators

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

Chapter 3: Operators, Expressions and Type Conversion

Chapter 3: Operators, Expressions and Type Conversion 101 Chapter 3 Operators, Expressions and Type Conversion Chapter 3: Operators, Expressions and Type Conversion Objectives To use basic arithmetic operators. To use increment and decrement operators. To

More information

Review of the C Programming Language for Principles of Operating Systems

Review of the C Programming Language for Principles of Operating Systems Review of the C Programming Language for Principles of Operating Systems Prof. James L. Frankel Harvard University Version of 7:26 PM 4-Sep-2018 Copyright 2018, 2016, 2015 James L. Frankel. All rights

More information

INDORE INDIRA SCHOOL OF CAREER STUDIES C LANGUAGE Class B.Sc. - IIND Sem

INDORE INDIRA SCHOOL OF CAREER STUDIES C LANGUAGE Class B.Sc. - IIND Sem UNIT- I ALGORITHM: An algorithm is a finite sequence of instructions, a logic and explicit step-by-step procedure for solving a problem starting from a known beginning. OR A sequential solution of any

More information

Multiple Choice Questions ( 1 mark)

Multiple Choice Questions ( 1 mark) Multiple Choice Questions ( 1 mark) Unit-1 1. is a step by step approach to solve any problem.. a) Process b) Programming Language c) Algorithm d) Compiler 2. The process of walking through a program s

More information

C Programming Class I

C Programming Class I C Programming Class I Generation of C Language Introduction to C 1. In 1967, Martin Richards developed a language called BCPL (Basic Combined Programming Language) 2. In 1970, Ken Thompson created a language

More information

C-LANGUAGE CURRICULAM

C-LANGUAGE CURRICULAM C-LANGUAGE CURRICULAM Duration: 2 Months. 1. Introducing C 1.1 History of C Origin Standardization C-Based Languages 1.2 Strengths and Weaknesses Of C Strengths Weaknesses Effective Use of C 2. C Fundamentals

More information

Unit 5. Decision Making and Looping. School of Science and Technology INTRODUCTION

Unit 5. Decision Making and Looping. School of Science and Technology INTRODUCTION INTRODUCTION Decision Making and Looping Unit 5 In the previous lessons we have learned about the programming structure, decision making procedure, how to write statements, as well as different types of

More information

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

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

More information

I Internal Examination Sept Class: - BCA I Subject: - Principles of Programming Lang. (BCA 104) MM: 40 Set: A Time: 1 ½ Hrs.

I Internal Examination Sept Class: - BCA I Subject: - Principles of Programming Lang. (BCA 104) MM: 40 Set: A Time: 1 ½ Hrs. I Internal Examination Sept. 2018 Class: - BCA I Subject: - Principles of Programming Lang. (BCA 104) MM: 40 Set: A Time: 1 ½ Hrs. [I]Very short answer questions (Max 40 words). (5 * 2 = 10) 1. What is

More information

Information Science 1

Information Science 1 Information Science 1 Simple Calcula,ons Week 09 College of Information Science and Engineering Ritsumeikan University Topics covered l Terms and concepts from Week 8 l Simple calculations Documenting

More information

Expressions and Precedence. Last updated 12/10/18

Expressions and Precedence. Last updated 12/10/18 Expressions and Precedence Last updated 12/10/18 Expression: Sequence of Operators and Operands that reduce to a single value Simple and Complex Expressions Subject to Precedence and Associativity Six

More information

Unit 3 Decision making, Looping and Arrays

Unit 3 Decision making, Looping and Arrays Unit 3 Decision making, Looping and Arrays Decision Making During programming, we have a number of situations where we may have to change the order of execution of statements based on certain conditions.

More information

Programming for Engineers Iteration

Programming for Engineers Iteration Programming for Engineers Iteration ICEN 200 Spring 2018 Prof. Dola Saha 1 Data type conversions Grade average example,-./0 class average = 23450-67 893/0298 Grade and number of students can be integers

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

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

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

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

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

PES INSTITUTE OF TECHNOLOGY (BSC) I MCA, First IA Test, November 2015 Programming Using C (13MCA11) Solution Set Faculty: Jeny Jijo

PES INSTITUTE OF TECHNOLOGY (BSC) I MCA, First IA Test, November 2015 Programming Using C (13MCA11) Solution Set Faculty: Jeny Jijo PES INSTITUTE OF TECHNOLOGY (BSC) I MCA, First IA Test, November 2015 Programming Using C (13MCA11) Solution Set Faculty: Jeny Jijo 1. (a)what is an algorithm? Draw a flowchart to print N terms of Fibonacci

More information

Module 4: Decision-making and forming loops

Module 4: Decision-making and forming loops 1 Module 4: Decision-making and forming loops 1. Introduction 2. Decision making 2.1. Simple if statement 2.2. The if else Statement 2.3. Nested if Statement 3. The switch case 4. Forming loops 4.1. The

More information

Variables and literals

Variables and literals Demo lecture slides Although I will not usually give slides for demo lectures, the first two demo lectures involve practice with things which you should really know from G51PRG Since I covered much of

More information

JAVA OPERATORS GENERAL

JAVA OPERATORS GENERAL 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

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

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

Informatics Ingeniería en Electrónica y Automática Industrial

Informatics Ingeniería en Electrónica y Automática Industrial Informatics Ingeniería en Electrónica y Automática Industrial Operators and expressions in C Operators and expressions in C Numerical expressions and operators Arithmetical operators Relational and logical

More information

Part I Part 1 Expressions

Part I Part 1 Expressions Writing Program in C Expressions and Control Structures (Selection Statements and Loops) Jan Faigl Department of Computer Science Faculty of Electrical Engineering Czech Technical University in Prague

More information

'C' Programming Language

'C' Programming Language F.Y. Diploma : Sem. II [DE/EJ/ET/EN/EX] 'C' Programming Language Time: 3 Hrs.] Prelim Question Paper Solution [Marks : 70 Q.1 Attempt any FIVE of the following : [10] Q.1(a) Define pointer. Write syntax

More information

Expressions and Data Types CSC 121 Spring 2015 Howard Rosenthal

Expressions and Data Types CSC 121 Spring 2015 Howard Rosenthal Expressions and Data Types CSC 121 Spring 2015 Howard Rosenthal Lesson Goals Understand the basic constructs of a Java Program Understand how to use basic identifiers Understand simple Java data types

More information

CS313D: ADVANCED PROGRAMMING LANGUAGE

CS313D: ADVANCED PROGRAMMING LANGUAGE CS313D: ADVANCED PROGRAMMING LANGUAGE Computer Science department Lecture 2 : C# Language Basics Lecture Contents 2 The C# language First program Variables and constants Input/output Expressions and casting

More information

MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION (Autonomous) (ISO/IEC Certified) MODEL ANSWER

MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION (Autonomous) (ISO/IEC Certified) MODEL ANSWER Important Instructions to examiners: 1) The answers should be examined by key words and not as word-to-word as given in the model answer scheme. 2) The model answer and the answer written by candidate

More information

Computers Programming Course 7. Iulian Năstac

Computers Programming Course 7. Iulian Năstac Computers Programming Course 7 Iulian Năstac Recap from previous course Operators in C Programming languages typically support a set of operators, which differ in the calling of syntax and/or the argument

More information

Object oriented programming. Instructor: Masoud Asghari Web page: Ch: 3

Object oriented programming. Instructor: Masoud Asghari Web page:   Ch: 3 Object oriented programming Instructor: Masoud Asghari Web page: http://www.masses.ir/lectures/oops2017sut Ch: 3 1 In this slide We follow: https://docs.oracle.com/javase/tutorial/index.html Trail: Learning

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

Chapter 12 Variables and Operators

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

More information

The C language. Introductory course #1

The C language. Introductory course #1 The C language Introductory course #1 History of C Born at AT&T Bell Laboratory of USA in 1972. Written by Dennis Ritchie C language was created for designing the UNIX operating system Quickly adopted

More information

Review of the C Programming Language

Review of the C Programming Language Review of the C Programming Language Prof. James L. Frankel Harvard University Version of 11:55 AM 22-Apr-2018 Copyright 2018, 2016, 2015 James L. Frankel. All rights reserved. Reference Manual for the

More information

Aryan College. Fundamental of C Programming. Unit I: Q1. What will be the value of the following expression? (2017) A + 9

Aryan College. Fundamental of C Programming. Unit I: Q1. What will be the value of the following expression? (2017) A + 9 Fundamental of C Programming Unit I: Q1. What will be the value of the following expression? (2017) A + 9 Q2. Write down the C statement to calculate percentage where three subjects English, hindi, maths

More information

CHRIST THE KING BOYS MATRIC HR. SEC. SCHOOL, KUMBAKONAM CHAPTER 9 C++

CHRIST THE KING BOYS MATRIC HR. SEC. SCHOOL, KUMBAKONAM CHAPTER 9 C++ CHAPTER 9 C++ 1. WRITE ABOUT THE BINARY OPERATORS USED IN C++? ARITHMETIC OPERATORS: Arithmetic operators perform simple arithmetic operations like addition, subtraction, multiplication, division etc.,

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

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

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

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

Module 2 - Part 2 DATA TYPES AND EXPRESSIONS 1/15/19 CSE 1321 MODULE 2 1

Module 2 - Part 2 DATA TYPES AND EXPRESSIONS 1/15/19 CSE 1321 MODULE 2 1 Module 2 - Part 2 DATA TYPES AND EXPRESSIONS 1/15/19 CSE 1321 MODULE 2 1 Topics 1. Expressions 2. Operator precedence 3. Shorthand operators 4. Data/Type Conversion 1/15/19 CSE 1321 MODULE 2 2 Expressions

More information

9/5/2018. Overview. The C Programming Language. Transitioning to C from Python. Why C? Hello, world! Programming in C

9/5/2018. Overview. The C Programming Language. Transitioning to C from Python. Why C? Hello, world! Programming in C Overview The C Programming Language (with material from Dr. Bin Ren, William & Mary Computer Science) Motivation Hello, world! Basic Data Types Variables Arithmetic Operators Relational Operators Assignments

More information

Department of Computer Science

Department of Computer Science Department of Computer Science Definition An operator is a symbol (+,-,*,/) that directs the computer to perform certain mathematical or logical manipulations and is usually used to manipulate data and

More information

Control Flow. COMS W1007 Introduction to Computer Science. Christopher Conway 3 June 2003

Control Flow. COMS W1007 Introduction to Computer Science. Christopher Conway 3 June 2003 Control Flow COMS W1007 Introduction to Computer Science Christopher Conway 3 June 2003 Overflow from Last Time: Why Types? Assembly code is typeless. You can take any 32 bits in memory, say this is an

More information

The Arithmetic Operators. Unary Operators. Relational Operators. Examples of use of ++ and

The Arithmetic Operators. Unary Operators. Relational Operators. Examples of use of ++ and The Arithmetic Operators The arithmetic operators refer to the standard mathematical operators: addition, subtraction, multiplication, division and modulus. Op. Use Description + x + y adds x and y x y

More information

The Arithmetic Operators

The Arithmetic Operators The Arithmetic Operators The arithmetic operators refer to the standard mathematical operators: addition, subtraction, multiplication, division and modulus. Examples: Op. Use Description + x + y adds x

More information

CS201- Introduction to Programming Latest Solved Mcqs from Midterm Papers May 07,2011. MIDTERM EXAMINATION Spring 2010

CS201- Introduction to Programming Latest Solved Mcqs from Midterm Papers May 07,2011. MIDTERM EXAMINATION Spring 2010 CS201- Introduction to Programming Latest Solved Mcqs from Midterm Papers May 07,2011 Lectures 1-22 Moaaz Siddiq Asad Ali Latest Mcqs MIDTERM EXAMINATION Spring 2010 Question No: 1 ( Marks: 1 ) - Please

More information

Full file at

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

More information

The C Programming Language. (with material from Dr. Bin Ren, William & Mary Computer Science)

The C Programming Language. (with material from Dr. Bin Ren, William & Mary Computer Science) The C Programming Language (with material from Dr. Bin Ren, William & Mary Computer Science) 1 Overview Motivation Hello, world! Basic Data Types Variables Arithmetic Operators Relational Operators Assignments

More information

The pixelman Language Reference Manual. Anthony Chan, Teresa Choe, Gabriel Kramer-Garcia, Brian Tsau

The pixelman Language Reference Manual. Anthony Chan, Teresa Choe, Gabriel Kramer-Garcia, Brian Tsau The pixelman Language Reference Manual Anthony Chan, Teresa Choe, Gabriel Kramer-Garcia, Brian Tsau October 2017 Contents 1 Introduction 2 2 Lexical Conventions 2 2.1 Comments..........................................

More information

Basic C Programming (2) Bin Li Assistant Professor Dept. of Electrical, Computer and Biomedical Engineering University of Rhode Island

Basic C Programming (2) Bin Li Assistant Professor Dept. of Electrical, Computer and Biomedical Engineering University of Rhode Island Basic C Programming (2) Bin Li Assistant Professor Dept. of Electrical, Computer and Biomedical Engineering University of Rhode Island Data Types Basic Types Enumerated types The type void Derived types

More information

Government Polytechnic Muzaffarpur.

Government Polytechnic Muzaffarpur. Government Polytechnic Muzaffarpur. Name of the Lab: COMPUTER PROGRAMMING LAB (MECH. ENGG. GROUP) Subject Code: 1625408 Experiment: 1 Aim: Programming exercise on executing a C program. If you are looking

More information

.Net Technologies. Components of.net Framework

.Net Technologies. Components of.net Framework .Net Technologies Components of.net Framework There are many articles are available in the web on this topic; I just want to add one more article over the web by explaining Components of.net Framework.

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

CS 159 Credit Exam. What advice do you have for students who have previously programmed in another language like JAVA or C++?

CS 159 Credit Exam. What advice do you have for students who have previously programmed in another language like JAVA or C++? CS 159 Credit Exam An increasing number of students entering the First Year Engineering program at Purdue University are bringing with them previous programming experience and a many of these students

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

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

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

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

More information

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

Computers Programming Course 11. Iulian Năstac

Computers Programming Course 11. Iulian Năstac Computers Programming Course 11 Iulian Năstac Recap from previous course Cap. Matrices (Arrays) Matrix representation is a method used by a computer language to store matrices of different dimension in

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

Operators & Expressions

Operators & Expressions Operators & Expressions Operator An operator is a symbol used to indicate a specific operation on variables in a program. Example : symbol + is an add operator that adds two data items called operands.

More information

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

Will introduce various operators supported by C language Identify supported operations Present some of terms characterizing operators Operators Overview Will introduce various operators supported by C language Identify supported operations Present some of terms characterizing operators Operands and Operators Mathematical or logical relationships

More information