1 FUNDAMENTALS OF COMPUTING & COMPUTER PROGRAMMING UNIT IV INTRODUCTION TO C Overview of C Constants, Variables and Data Types Operators and Expressions Managing Input and Output operators Decision Making - Branching and Looping. 2 MARKS 1. What are the different data types available in C? There are four basic data types available in C. 1. int 2. float 3. char 4. double 2. What are Keywords? Keywords are certain reserved words that have standard and pre-defined meaning in C. These keywords can be used only for their intended purpose.
2 3. What is an Operator and Operand? An operator is a symbol that specifies an operation to be performed on operands. Example: *, +, -, / are called arithmetic operators. The data items that operators act upon are called operands. Example: a+b; In this statement a and b are called operands. 4. What is Ternary operators or Conditional operators? Ternary operators is a conditional operator with symbols? and : Syntax: variable = exp1? exp2 : exp3 If the exp1 is true variable takes value of exp2. If the exp2 is false, variable takes the value of exp3. 5. What are the Bitwise operators available in C? & - Bitwise AND - Bitwise OR ~ - One s Complement >> - Right shift << - Left shift ^ - Bitwise XOR are called bit field operators Example: k=~j; where ~ take one s complement of j and the result is stored in k.
3 6. What are the logical operators available in C? The logical operators available in C are && - Logical AND - Logical OR! - Logical NOT 7. What is the difference between Logical AND and Bitwise AND? Logical AND (&&): Only used in conjunction with two expressions, to test more than one condition. If both the conditions are true the returns 1. If false then return 0. AND (&): Only used in Bitwise manipulation. It is a unary operator. 8. What is the difference between = and == operator? Where = is an assignment operator and == is a relational operator. Example: while (i=5) is an infinite loop because it is a non zero value and while (i==5) is true only when i=5. 9. What is type casting? Type casting is the process of converting the value of an expression to a particular data type. Example:
4 int x,y; c = (float) x/y; where a and y are defined as integers. Then the result of x/y is converted into float. 10. What is conversion specification? The conversion specifications are used to accept or display the data using the INPUT/OUTPUT statements. 11. What is the difference between a and a? a is a character constant and a is a string. 12. What is the difference between if and while statement? if while (i) It is a conditional (i) It is a loop control statement statement (ii) If the condition is true, it (ii) Executes the statements within executes the some statements. (iii) If the condition is false then it stops the execution the statements. while block if the condition is true. (iii) If the condition is false the control is transferred to the next statement of the loop. 13. What is the difference between while loop and do while loop?
5 In the while loop the condition is first executed. If the condition is true then it executes the body of the loop. When the condition is false it comes of the loop. In the do while loop first the statement is executed and then the condition is checked. The do while loop will execute at least one time even though the condition is false at the very first time. 14. What is a Modulo Operator? % is modulo operator. It gives the remainder of an integer division Example: a=17, b=6. Then c=%b gives How many bytes are occupied by the int, char, float, long int and double? int - 2 Bytes char - 1 Byte float - 4 Bytes long int - 4 Bytes double - 8 Bytes 16. What are the types of I/O statements available in C? There are two types of I/O statements available in C. Formatted I/O Statements Unformatted I/O Statements 17. What is the difference between ++a and a++?
6 ++a means do the increment before the operation (pre increment) a++ means do the increment after the operation (post increment)example: a=5; x=a++; /* assign x=5*/ y=a; /*now y assigns y=6*/ x=++a; /*assigns x=7*/ 18. What is a String? String is an array of characters. 19. What is a global variable? The global variable is a variable that is declared outside of all the functions. The global variable is stored in memory, the default value is zero. Scope of this variable is available in all the functions. Life as long as the program s execution doesn t come to an end. 20. What are the Escape Sequences present in C \n - New Line \b - Backspace \t - Form feed \ - Single quote \\ - Backspace
7 \t - Tab \r - Carriage return \a - Alert \ - Double quotes 21. Construct an infinite loop using while? while (1) Here 1 is a non zero, value so the condition is always true. So it is an infinite loop. 22. What will happen when you access the array more than its dimension? When you access the array more than its dimensions some garbage value is stored in the array. 23. Write the limitations of getchar( ) and sacnf( ) functions for reading strings (JAN 2009) getchar( ) To read a single character from stdin, then getchar() is the appropriate. scanf( ) scanf( ) allows to read more than just a single character at a time.
8 24. What is the difference between scanf() and gets() function? In scanf() when there is a blank was typed, the scanf() assumes that it is an end. gets() assumes the enter key as end. That is gets() gets a new line (\n) terminated string of characters from the keyboard and replaces the \n with \ What is a Structure? Structure is a group name in which dissimilar data s are grouped together. 26. What is meant by Control String in Input/Output Statements? Control Statements contains the format code characters, specifies the type of data that the user accessed within the Input/Output statements. 27. What is Union? Union is a group name used to define dissimilar data types. The union occupies only the maximum byte of the data type. If you declare integer and character, then the union occupies only 2 bytes, whereas structure occupies only 3 bytes. 28. What is the output of the programs given below? main() main() float a; float a;
9 int x=6, y=4; int x=6, y=4; a=x\y; a=(float) x\y; printf( Value of a=%f, a); printf( Value of a=%f,a); Output: Output: Declare the Structure with an example? struct name char name; int age; float salary; e1, e2; 30. Declare the Union with an example? union name char name; int age;
10 float salary; e1, e2; 31. What is the output of the following program when, the name given with spaces? main() char name; printf( \n name\n ); scanf( %s, name); printf( %s,name); Output: Lachi (It only accepts the data upto the spaces) 32. What is the difference between while(a) and while(!a)? while(a) means while(a!=0) while(!a) means while(a==0) 33. Why we don t use the symbol & symbol, while reading a String through scanf()? The & is not used in scanf() while reading string, because the character variable itself specifies as a base address. Example: name, &name both the declarations are same.
11 34. What is the difference between static and auto storage classes? Storage Initial value Static Memory Zero Auto Memory Garbage value Scope Life Local to the block in Local to the block in which the variables is which the variable is defined defined. Value of the variable persists between different function calls. The block in which the variable is defined. 35. What is the output of the program? main() increment() increment(); static int i=1; increment(); printf( %d\n,i) increment(); i=i+1; OUTPUT: Why header files are included in C programming? This section is used to include the function definitions used in the program. Each header file has h extension and include using # include directive at the beginning of a program.
12 37. List out some of the rules used for C programming. All statements should be written in lower case letters. Upper case letters are only for symbolic constants. Blank spaces may be inserted between the words. This improves the readability of statements. It is a free-form language; we can write statements anywhere between and. a = b + c; d = b*c; (or) a = b+c; d = b*c; Opening and closing braces should be balanced. 38. Define delimiters in C. : Delimiters Colon Use Useful for label ; ( ) [ ] #, Semicolon Parenthesis Square Bracket Curly Brace Hash Comma Terminates Statement Used in expression and functions Used for array declaration Scope of statement Preprocessor directive Variable Separator
13 39. What do you mean by variables in C? A variable is a data name used for storing a data value. Can be assigned different values at different times during program execution. Can be chosen by programmer in a meaningful way so as to reflect its function in the program. Some examples are: Sum percent_1 class_total 40. List the difference between float and double datatype. S No Float Double Float / Double 1 Occupies 4 bytes in memory Occupies 8 bytes in memory 2 Range : 3.4 e-38 to Range : 1.7 e-308 to 1.7e e+38 Format Specifier: % lf 4 Format Specifier: % f Example : float a; Example : double y; There exists long double having a range of 3.4 e to 3.4 e and occupies 10 bytes in memory. Example: long double k; 41. Differentiate break and continue statement S No break continue 1 Exits from current block Loop takes next iteration / loop 2 Control passes to beginning Control passes to next of loop 3
14 statement Terminates the program Never terminates the program 42. List the types of operators. S No Operators Types Symbolic Representation 1 Arithmetic operators =, -, *, / and % Relational operators Logical operators Increment and Decrement operators Assignment operators Bitwise operators Comma operator Conditional operator >, <, ==, >=, <= and!= &&, and! ++ and =, + =, - =, * =, / =, ^ =, ; =, & = &,, ^, >>, <<, and ~,? : 43. Distinguish between while..do and do..while statement in C. (JAN 2009) While..DO (i) Executes the statements within the while block if only the condition is true. (ii) The condition is checked at the starting of the loop DO..while (i) Executes the statements within the while block at least once. (ii) The condition is checked at the end of the loop 44. Compare switch( ) and nestedif statement.
15 S No switch( ) case nested if 1 Test for equality ie., only constant It can equate relational (or) 2 values are applicable. logical expressions. 3 4 No two case statements in same switch. Character constants are automatically converted to integers. In switch( ) case statement nested if can be used. Same conditions may be repeated for a number of times. Character constants are automatically converted to integers. In nested if statement switch case can be used. 45. Distinguish Increment and Decrement operators. S No Increment ++ Decrement -- 1 Adds one to its operand Subtracts one from its operand 2 Equivalent x = x + 1 Equivalent x = x Either follow or precede operand Either follow or precede 4 operand Example : ++x; x++; Example : --x; x--; 46. Give the syntax for the for loop statement for (Initialize counter; Test condition; Increment / Decrement) statements;
16 Initialization counter sets the loop to an initial value. This statement is executed only once. The test condition is a relational expression that determines the number of iterations desired or it determines when to exit from the loop. The for loop continues to execute as long as conditional test is satisfied. When condition becomes false, the control of program exists the body of the for loop and executes next statement after the body of the loop. The increment / decrement parameter decides how to make changes in the loop. The body of the loop may contain either a single statement or multiple statements. 47. What is the use of sizeof( ) operator? The sizeof ( ) operator gives the bytes occupied by a variable. No of bytes occupied varies from variable to variable depending upon its data types. Example: int x,y; printf( %d,sizeof(x)); Output: What is a loop control statement? Many tasks done with the help of a computer are repetitive in nature. Such tasks can be done with loop control statements.
17 49. What are global variable in C? This section declares some variables that are used in more than one function. such variable are called as global variables. It should be declared outside all functions. 50. Write a program to swap the values of two variables (without temporary variable). #include <stdio.h> #include <conio.h> void main( ) int a =5; b = 10; clrscr( ); prinf( Before swapping a = %d b = %d, a, b); a = a + b; B = a b; a = a b; prinf( After swapping a = %d b = %d, a,b); getch( ); Output:
18 Before swapping a = 5 b = 10 After swapping a = 10 b = Write short notes about main ( ) function in C program. (MAY 2009) Every C program must have main ( ) function. All functions in C, has to end with ( ) parenthesis. It is a starting point of all C programs. The program execution starts from the opening brace and ends with closing brace, within which executable part of the program exists. Part B-16 marks 1. Explain in detail about C declarations and variables. C is portable, structured programming language. It is robust, fast.extensible. It is used for complex programs. The root of all modern language is ALGOL (1960). BCPL (Basic Combined Programming Language) a user friendly OS providing powerful development tools developed from BCPL. Assembler tedious long and error prone. A new language ``B'' a second attempt. c A totally new language ``C'' a successor to ``B''. c By 1973 UNIX OS almost totally written in ``C''.
19 Characteristics of C Some of C's characteristics that define the language and also have lead to its popularity as a programming language. Small size Supports variety of data types and a set of operators. Extensive use of function calls Enables the implementation of hierarchical and modular programming with the help of functions. C can extend itself by addition of functions to its library continuously. Structured language Low level (BitWise) programming readily available Pointer implementation - extensive use of pointers for memory, array, structures and functions. C has now become a widely used professional language for various reasons. It has high-level constructs. It can handle low-level activities. It produces efficient programs. It can be compiled on a variety of computers. Basic structure of C program
20 Documentation Section Link section Definition section Global declaration section main() function section Declaration part Executable part Sub program section Function 1 Function 2 (user defined functions) Function n 2. Explain in detail about the constants, expressions and statements in C. CONSTANTS Constants in C are applicable to values, which do not change during the execution of a program. C constants are classified as o Numeric constants Integer constants
21 Real constants o Character constants Single character constants String constants 1. Numeric constants a. Integer constants Sequence of numbers from 0 to 9 without decimal point or fractional part or any other symbols. Minimum 2 bytes, maximum 4 bytes. It may be positive or negative or zero Eg:10,+30,-15 b. Real constants floating point constants many parameters are defined in real constants like height,length,distance. Eg:2.5,3.14 It can be written in exponential notation. 2. Character constants a. Single character constant Single character Single digit or single special symbol or white space enclosed within a pair of single quote marks. Characters constants have integer values known as ASCII values. Eg: a, 8, u b. String constants Sequence of characters enclosed within double quote marks. String may be a combination of all kinds of symbols. Eg: hello, India, 444, a
22 2. Expressions: An expression represents a single data item, such as number or a character. Logical conditions that are true or false are represented by expressions. Example: a = p q / 3 + r * Statements Assignment Statements Definition and examples Null Statements Definition and examples Block of statements Definition and examples Expression statements Definition and examples Declaration statements Definition and examples 3. Discuss about the various data types in C. (MAY 2009) C support variety of data types. Data is represented using numbers or characters. C is a so called type safe programming language, that is, any variable needs to be assigned a supported data type. C supports the following data types: /* elementary data types */ bool char short int double float long signed char, int, short, unsigned char, int, short, /* customized or non-elementary data types */ struct enum Data types Size(bytes) Format specifier
23 Char 1 %c Unsigned char 1 %c Short or int 2 %i or %d Unsigned int 2 %u Long 4 %ld Unsigned long 4 %lu Float 4 %f or %g Double 8 %lf Long double 10 %lf Declaring variables Should be done in declaration part of the program. Compiler obtains the variable name. It tells the compiler the data type of the variable being declared and helps in allocating the memory. Syntax: data type variable name int age; Initializing variables Variables declared can be assigned or initialized using an assignment operator =. Syntax: Variable-name = constant Or Data-type variable name = constant
24 Eg: int y=2; int x, y,z; Example program: Addition of two numbers #include<stdio.h> #include<conio.h> void main () int a,b,c; printf( enter the values of a and b ); scanf( %d %d,&a,&b); c=a+b; printf( the value of c is=%d,c); getch(); 4. Describe the various types of operators in C language along with its priority. An operator indicates an operation to be performed on data that yields a value. An operator is a symbol which helps the user to command the computer to do a certain mathematical or logical manipulations. Operators are used in C language program to operate on data and variables. C has a rich set of operators which can be classified as 1. Arithmetic operators +,-,*,/ and % 2. Relational Operators >,<,==,>=,<=,!= 3. Logical Operators &&,,! 4. Increments and Decrement Operators ++,-- 5. Assignment Operators = 6. Bitwise Operators &,/,>>,<<,~ 7. Comma operator,
25 8. Conditional Operators?: 1. Arithmetic Operators All the basic arithmetic operations can be carried out in C. All the operators have almost the same meaning as in other languages. Both unary and binary operations are available in C language. Unary operations operate on a singe operand, therefore the number 5 when operated by unary will have the value 5. Operator Meaning + Addition or Unary Plus Subtraction or Unary Minus * Multiplication / Division % Modulus Operator Examples of arithmetic operators are x + y x - y -x + y a * b + c -a * b here a, b, c, x, y are known as operands. The modulus operator is a special operator in C language which evaluates the remainder of the operands after division. 2. Relational Operators Often it is required to compare the relationship between operands and bring out a decision and program accordingly. This is when the relational operator comes into picture. C supports the following relational operators. Operator Meaning < is less than
26 <= is less than or equal to > is greater than >= is greater than or equal to == is equal to!= is not equal to A simple relational expression contains only one relational operator and takes the following form. exp1 relational operator exp2 Where exp1 and exp2 are expressions, which may be simple constants, variables or combination of them. Given below is a list of examples of relational expressions and evaluated values. 3. Logical Operators C has the following logical operators, they compare or evaluate logical and relational expressions. Operator Meaning && Logical AND Logical OR! Logical NOT (&&) Logical AND This operator is used to evaluate 2 conditions or expressions with relational operators simultaneously. If both the expressions to the left and to the right of the logical operator is true then the whole compound expression is true. Example a > b && x = = 10 The expression to the left is a > b and that on the right is x == 10 the whole expression is true only if both expressions are true i.e., if a is greater than b and x is equal to Increment and decrement operator: It is used to increment or decrement the value Eg:i++;
27 j--; 4. Assignment Operators The Assignment Operator evaluates an expression on the right of the expression and substitutes it to the value or variable on the left of the expression. Example x = a + b Here the value of a + b is evaluated and substituted to the variable x. In addition, C has a set of shorthand assignment operators of the form. var oper = exp; Here var is a variable, exp is an expression and oper is a C binary arithmetic operator. The operator oper = is known as shorthand assignment operator 5. Bitwise operator Operator Meaning >> right shift << left shift ^ bitwise XOR ~ one s complement & bitwise AND bitwise OR 7. Comma operator It is used to separate two or more expressions. Eg:a=2,b=4,c=a+b; 8. Conditional operator Syntax: Condition?(expression1) expression2);
28 If the condition true,the expression 1 is evaluated. If the condition is false,the expression2 is evaluated. 5.Explain about the various decision making statements in C language. (JAN 2009/FEB2010) Program is the execution of one or more instructions. Based on the condition, the order of execution may change. On the basis of applications it is essential to Alter the flow of a program. Test the logical conditions. Control the flow of execution as per the selection. C language supports the control statements as listed below. if statement if-else if-else.if switch() case 1. if statement: syntax: if(condition) statement; eg: if (a>b) printf( a is greater ); 2. if-else: Syntax: if(condition is true) execute statement1; else execute statement2; Eg: if (a>b)
29 printf( a is greater ); else printf( b is greater ); 3. Nested if-else: Rules: Nested if else can be chained with one another. If condition is false, control passes to else block. If one of the if statement satisfies the condition, other nested else if will not be executed. Syntax: if ( condition) statement1; statement2; else if( condition) Statement3; Statement4; else Statement5; Statement6; Eg: finding biggest of three numbers. #include<stdio.h>
30 #include<conio.h> main() int a,b,c,big; clrscr(); printf( Enter three numbers ); scanf( %d %d %d,&a,&b,&c); if(a>b) if(a>c) big=a; else big=c; else if(b>c) big=b; else big=c; printf( \n Biggest number is %d,big); getch(); Output: Enter three numbers: 18,-5, 13 Biggest number is 18
31 4. switch() It is multiway branch statement. It requires only one argument of any data type, which is checked with number of case options. If value matches with case constant, particular case statement is executed. If not matched, default is executed. Every case terminates with : symbol. break is used to exit from current case. Syntax: switch (variable or expression) case constant A: Statement; break; case constant B: Statement; break; default: statement; Eg: Program to find value of y #include<stdio.h> #include<conio.h> #include<math.h> main() int n;
32 float x,y; clrscr(); printf( \n Enter values to x and n: ); scanf( %f %d,&x,&n); switch(n) case 1: y=1+x; break; case 2: y=1-x; break; case 3: y=1+pow(x,n) break; default: y=1+n*x; break; printf( \n value of y(x,n)=%f),y); getch(); Output: Enter value to x and n: Value of y(x,n)=3.10
33 break statement: It allows programmers to terminate the loop. It skips from loop or block in which it is defined. continue statement: It is opposite to break. Continuing next iteration of loop statements. It does not terminate, bit it skips the statements. goto statement: It does not require any condition. It passes control anywhere in the program Syntax: goto label; Eg: even or odd using goto. #include<stdio.h> #include<conio.h> #include<stdlib.h> main() int x; clrscr(); printf( \n Enter a number: ); scanf( %d,&x); if( x%2==0) goto even;
34 else goto odd; even: printf( \n %d is even number ); return; odd: printf( \n %d is odd number ); Output: Enter a number: 5 5 is odd number. Difference between break and continue break Exits from current block or loop Control passes to nest statement Terminates the program continue Loop takes next iteration Control passes to the beginning of loop Never terminates the program 6. Write short notes on the following: (JAN 2009) for loop while loop dowhile loop Switch case (MAY 2009/FEB 2009/FEB 2010)
35 Branching and looping are used for repetitive tasks. Loop: A loop is defined as a block of statements which are repeatedly executed for certain number of times. Terms in loop are Loop variable Initialization Incrimination or decrimination Loops in C language are for() while() do while() Formats: a) for loop It allows for executing a set of instructions until a certain condition is satisfied. Syntax: for (initialize;test condition;re-evaluation parameter) Statement; Statement; for (;;) infinite loop no arguments for (a=0;a<=20;) infinite loop a is neither increased nor decreased for( a=0;a<=10;a++) displays value value of a is displayed printf( %d,a); from 0 to 10 from o to 10 for(a=10;a>=0;a--) printf( %d,a) displays from 10 to 0 value a is decreased from 10 to 0
36 Eg: display numbers from 1 to 15 using for loop #include<stdio.h> #include<conio.h> main() int i; Output: clrscr(); for( i=1;i<=15;i++) printf( %d,i);
37 Nested for loops: Using loop within loop Eg: finding perfect cubesof1,2,3,4 #include<math.h> main() int i,j,k; clrscr(); printf( Enter a number ); scanf( %d,&k); for(i=1;i<k;i++) for(j=1;j<=i;j++) if(i==pow(j,3)) printf( \n Number: %d & its cube :%d j,i); Output: Enter a number: 1000 Number:1 & its cube :1 Number:2 & its cube :8
38 Number:3 & its cube :27 Number:4 & its cube :64 b) While loop: syntax: while (test condition) Body of the loop; Loop statements will be executed till the condition is true. Test condition is evaluated and if the condition is true, body of the loop is executed. When condition becomes false the execution will be out of the loop. Eg: add 10 consecutive numbers starting from 1 main() int a=1;sum=0; clrscr(); while(a<=10) printf( %d,a); sum=sum+a; a++; printf( \n Sum of 10 numbers:%d,sum);
39 Output: Sum of 10 numbers: 55 c) do-while loop: syntax: do Statement; while (condition); condition is checked at the end of the loop. do-while loop will execute atleast one time even if the condition is false initially. do-while loop executes until the condition becomes false. Eg: main() int i=1; clrscr(); do printf( \n This is a program of do while loop ); i++; while(i<=5);
40 Output: This is a program of do while loop This is a program of do while loop This is a program of do while loop This is a program of do while loop This is a program of do while loop d) do while statement with while loop syntax: do while(condition) Statements; while(condition); Eg: Print values from 1 to 5 using while statement in do while loop main () int x=0; clrscr(); do while(x<5) x++; printf( \t %d,x); while(x<1); Output
41 7. Explain briefly about the input and output function in C. (MAY 2009/FEB 2009) Input/Output functions are classified into two types. They are, Formatted functions Unformatted function Formatted functions Read and write all types of data values. Require conversion symbol to identify the data type. Return the values after execution. Unformatted functions Only work with character data type. Do not require conversion symbol for identification of data type. Return values are always same. Input/Output Functions Formatted Functions Unformatted Functions Input Output Input Output scanf() printf() getch() Formatted Functions: 1. printf () statement: getche() getchar() gets() Prints all types of data values to the console. putch() putchar() put()
42 Requires conversion symbol and variable names to print the data. Eg: main () int x=2; float y=2.2; char z= c ; printf( %d %f %c,x,y,z); Output c 2.scanf () statement Reads all type of data values It is used for run time assignment of variables. Requires conversion symbol to identify the data to be read Syntax: scanf( %d %f%c,&a,&b,&c); &-address operator-: prints the memory location of the variable. It indicates memory location,so that the value read would be placed at that location. It also returns values. Return value is exactly equal to the number of values correctly read. If any mismatch error will shown. Eg; #include<stdio.h> #include<conio.h>
43 main() int a; clrscr(); printf( Enter the value of A ); scanf( %c,&a); printf( A=%c,a); Output: Enter the value of A =8 A=8 Escape Sequences: printf(),scanf() statements follow a combination of characters called as escape sequences.it starts with \ \ n newline \ b backspace \ f formfeed \ singlequote \\ backslash \0 NULL \ t horizontal tab
44 \ r carriage return \ a alert(bell) \ double quotes \ v vertical tab \? question mark Eg:Average of three real numbers. #include<stdio.h> #include<conio.h> main() float a,b,c,d; clrscr(); printf( Enter three float numbers:\n ); scanf( \n %f %f %f,&a,&b,&c); d=a+b+c; printf( \n Average of given numbers:%f,d/3); Output: Enter three float numbers: Average of given numbers: 3.5 Unformatted Functions: There are three types of I/O functions. 1) Character I/O
45 2) String I/O 3) File I/O 1. Character I/O a) getchar() It reads character type data from the standard input. It reads one character at a time till the user presses the enter key. b) putchar() It prints one character on the screen at a time, which is read by the standard input. c) getch() and getche() These functions read any alphanumeric characters from the standard input device. Character entered is not displayed by getch() function d) putch() It prints any alphanumericcharacter taken by the standard input device. 2.String I/O a) gets() It is used for accepting any string through stdin keyboard until enter key is pressed. stdio.h is needed for implementing the above function. b) puts() It prints the string or character array. c) cgets() It reads strings from the console.
46 Syntax: cgets(char *st); d. cputs() It displays string on the console. Syntax : cputs(char *st); 3.File I/O fprintf() - write values to files. fscanf() - read values from files. getc() - reads a single character from operand file and moves the file pointer. putc()- writea single character into a file. fgetc() - reads a character and increase the file pointer position. fputc() - writes character to file shown by the file pointer. fgets() - reads the string. fputs() - write the string to operand file. putw() - write an integer value to file. getw() - returns the integer value and increase the pointer. Commonly used library functions: a) clrscr() - clear the screen -> conio.h b) exit () - terminates the program->process.h c) sleep() -pause the execution of program for a given number of seconds-dos.h d) system () - helpful in executing different dos.