Vous êtes sur la page 1sur 28

CHAPTER-4.1 C FUNDAMENTALS:Programming, High Level Languages, Compiling Programs, Integrated Development Environment ( Ide ) Q1) What is a computer program?

Ans: Computer program is a collection of instructions which are necessary to solve a specific problem. Q2) What is an algorithm? Ans: The step by step procedure to solve a problem is known as algorithm. Q3) Give an example for algorithm? Ans: step0:start step1:read a number step2:if number%2 is zero then print number is even step3.else print number is odd. step4:end Q4) What is high level language? Ans: A language which is easy to read and understand by the programmer. Q5) What is low level language? Ans: A language which is in low level format( Binary form). Q6) Which is low level language? Ans: Assembly level language is an example of low level languages. Q7) Which are high level languages? Ans: Fortran, C is an example of high level languages. Q8) Which are operating systems? Ans: Microsoft Windows XP,LINUX. Q9) What is a compiler? Ans: Compiler is a software program which translates complete high level program into machine level code. Q10) What is an assembler ? Ans: Assembler is a software program which translates assembly level program in to machine level code.

Q11) What is meant by building a program? Ans: The process of compiling and linking a program is often called building a program. Q12) What is an integrated development environment(IDE) ? Ans: The process of editing, compiling, linking ,debugging and executing programs is known as an IDE. Q11) Give an example of IDE under ms-dos? Ans: Under ms-dos, tc is a popular IDE. Q12) Give an example of IDE under linux? Ans: KYLIX is a popular IDE for developing applications under LINUX. Q13) Give an example of IDE under Mac OS X? Ans: Code Warrior and Xcode are two IDE's that are used by pragrammers. Q14) What is an interpreter? Ans: An interpreter is a software which translates line by line of high level program into machine code. Q15) What is a comment? Ans: A comment serves to tell the reader just what the programmer had in mind when he/she wrote a particular program. Q16) How to write a comment in C? Ans: Comment should be written in C as below /* it is comment line */ Q17) How to compile a program in linux OS? Ans: $ gcc filename.c or $ cc file name.c if you are using unix C compiler the command is 'cc' instead of 'gcc'. Q18) How to compile a program using TC in MS-DOS? Ans: By pressing Alt+F9 in TC IDE. Q19) How to assign a different name to executable file in LINUX OS? Ans: "o"(that's the letter O) which is followed by the name of the executable file. example: gcc filename.c -o executable file name Q20) How to terminate a statement in C?

Ans: All statements in C must be terminated by semicolon ( ; ).

MULTIPLE CHOICE QUESTIONS 1. C is a ---a. Structured progarmming Language b. Object oriented programming language c. Machine language d. Assembly language 2. The execution of a c program begins at a. main() b. scanf() c. printf() d. #include<stdio.h> 3. Which one of the following is valid file name in c a. system b. system.c c. system.cpp d. system.java 4. Which of the following is a intermediary file generated during the execution of c program? a. .c b. .obj c. .exe d. .bak 5. Which of the following is the correct form of writing comments? a. /*comment*/ b /*comment/* c. */comment/* d. */comment*/

CHAPTER 4.2 Variables, Constant,Data Types, Arithmetic Expressions, Input & Output Functions Q1) What is input function ? Ans: It is used to read values from input device . Q2) What is output function ? Ans: It is used to display output of a program Q3) What is a Variable ? Ans: A variable is a data name that is used to store a value. Q4) What is Constant? Ans: Constant is a fixed values that do not change during the execution of a program. Q5) What is data type ? Ans: Which indicates type of data. Q6) Ans: What are the rules to define a variable ? It must begin with a letter, or with underscore. It must not be a keyword. It must not contain white space or special characters. It can have digits at middle or end.

Q7) Give few examples for valid variable names? Ans: T_raise, delhi, x1, ph_value, mark, sum1, distance Q8) Is char a valid variable name? Ans: No, char is a keyword Q9) Is price$ a valid variable name? Ans: NOT VALID, dollar sign is illegal. Q10) Is 'group one' a valid variable name? Ans: NOT VALID blank space not permitted. Q11) Is int_type a valid variable name? Ans: valid, keyword may be a part of a name. Q12) What are the data types that ANSI c supports? Ans: ANSI c supports three classes of data types .they are

1. Primary (or fundamental/ primitive)data type 2. Derived data types 3. User defined data types. Q13) What are primary data types ? Ans : Char , int , long , float & double. Q14) What are derived data types ? Ans : Array , pointer. Q15) What are user defined data types. Ans : Structure, union and enum Q16) What is the size and range of the basic data types? Ans: The size and range of the basic data types are: Datatype int long int char float double size (bytes) 2 4 1 4 8 range -32,768 to +32767 -231 to 231-1 -128 to +127 3.4e-38 to 3.4e+38 1.7e-308to1.7e+308

Q17) What is the size and range of short int(or)signed short int,long int (or)signed long int? Ans: DATA TYPE SIZE RANGE Short Int (or) signed short int 2 -215 TO +215-1 Long Int (or) signed long int 4 -231 to 231-1 Q18) How many types of constants exist in c? Ans: C has two types of constants. Those are 1. Numeric constants 2. Character constants Q19) How many types of numeric constants exist in c? Ans: There are two types of numeric constants. They are: 1. Integer constants 2. Real constants Q20) How many types of character constants exist in? Ans: There are two types of character constants. Those are 1. Single character constants 2. String constants

Q21) Is embedded spaces, commas and non digit characters are permitted between decimal integer constants? Ans: No, embedded spaces, commas and non digit characters are NOT permitted between decimal integer constants. Q22) Is '20,000' a valid decimal integer constant? Ans: Not valid Q23) Give few examples of octal integer constants? Ans: 037, 0435, 0551. Q24) Give few examples of hexa decimal integer constants? Ans: 0x2, 0x9f, 0xbcd, ox1234. Q25) Give few examples of real type constants? Ans: 0.0083,-.75,435.36,+247.008 Q26) Give few examples of single character type constant? Ans: '5', 'x', ';' Q27) Give few examples of string constant? Ans: rana, 123, seetha123. Rama Rao . Q28) What are the basic escape sequence characters & meaning ? \a --- alarm \b ----- BackSpace \f ---- form feed \n --- newline \r ---- Carriage Return \t ---- Tab \v --- Vertical Tab Q29) What is an integer expression? Ans: When both the operands in an expression are integers then the expression is known as an integer expression. Q30) Let a=14, b=4 what will be the output for the following a) a-b b) a+b c) a*b d) a/b e) a%b Ans: a) 10 b) 18 c) 56 d) 3 e) 2 Q31) When an expression is called mixed mode arithmetic?

Ans: When one of the operands is real and the other is integer, the expression is called mixed mode arithmetic. Q32) What will be the value of c,d,e & f in the below code. float c=15/10.0 & int d=15/10; float e = 15/10 and float f= 15.0/10.0; Ans: c = 1.5 d=1 e = 1.0,f = 1.5. OUTPUT PREDICTION 1. What will be the output of the following program : int main() { printf("%%",7); return(0); } What will be the output of the following program : int main() { printf("//",5); return(0); } What will be the output of the following program : int main() { printf("d%",8); return(0); } What will be the output of the following program : int main() { printf("%d"+0,123); return(0); } What will be the output of the following program : int main() { printf("%d"+1,123); return(0); }

2.

3.

4.

5.

6.

What will be the output of the following program : int main() { printf("%d",printf("Hi!")+printf("Bye")); return(0); } What will be the output of the following program : int main() { printf("%d",printf("")+printf("")); return(0); } What will be the output of the following program : int main() { printf("Hi Friends"+3); return(0); } What will be the output of the following program : int main() { printf("D For ") + printf("DOG"); return(0); } What will be the output of the following program : 10. int main() { printf("\/\*\-*\/"); return(0); } What will be the output of the following program : int main() { int main=7; { printf("%d",main); return main;

7.

8.

9.

10.

11.

} printf("Bye"); return(0); } 12. What will be the output of the following program : int main() { printf("Work" "Hard"); return(0); } What will be the output of the following program : int main() { char str[]="%d"; int val=25; printf(str,val); return(0); } What will be the output of the following program : int main() { int val=10; printf("%d",val+1,"%d",val--); return(0); } 15. What will be the output of the following program [NOTE : ASSUME 2 values are entered by the user are stored in the variables 'val' & 'num' respectively] : int main() { int val=5,num; printf("%d",scanf("%d %d",&val,&num)); return(0); } What will be the output of the following program : #define Compute(x,y,z) (x+y-z) int main() { int x=2,y=3,z=4; printf("%d",Compute(y,z,(-x+y)) * Compute(z,x,(-y+z)));

13.

14.

16.

return(0); } 17. What will be the output of the following program : int main() { int m=10,n=20; printf("%d %d %d",m/* M */,/* N */n,m*/* Compute m*n */n); return(0); } What will be the output of the following program : int main() { int val=97; "Printing..."+printf("%c",val); return(0); } What will be the output of the following program : int main() { int val=5; val=printf("C") + printf("Skills"); printf("%d",val); return(0); } What will be the output of the following program : int main() { int val=5; printf("%*d",val,val); return(0); } What will be the output of the following program : int main() { printf("%f",123.); return(0); }

18.

19.

20.

21.

22.

What will be the output of the following program : int main() { char str[]="look at me"; printf("%d",sizeof str); return(0); } What will be the output of the following program : int main() { char str[]="look at me"; printf("%d",-sizeof(str)); return(0); } What will be the output of the following program : int main() { printf("%d",!(100==100)+1); return(0); } What will be the output of the following program : int main() { int x=5,y=6,z=2; z/=y/z==3?y/z:x*y; printf("%d",z); return(0); } What will be the output of the following program : int main() { printf("%d %d %d",5,!5,25-!25); return(0); } What will be the output of the following program : int main() { int a=500,b=100,c=30,d=40,e=19;

23.

24.

25.

26.

27.

a+=b-=c*=d/=e%=5; printf("%d %d %d %d %d",a,b,c,d,e); return(0); } 28. What will be the output of the following program : int main() { int a=500,b=100,c=30,d=40,e=19; if ((((a > b) ? c : d) >= e) && !((e <= d) ? ((a / 5) == b) : (c == d))) printf("Success"); else printf("Failure"); return(0); } What will be the output of the following program : int main() { int a=1,b=2,c=3,d=4; printf("%d",!a?b?!c:!d:a); return(0); } What will be the output of the following program [NOTE : 3 values entered by the user are:100 200 300] : int main() { int a=1,b=2,c=3; scanf("%d %*d %d",&a,&b,&c); printf("a=%d b=%d c=%d",a,b,c); return(0); } What will be the output of the following program [NOTE : THE USER INPUT IS:Dear Friends, What is the output?] : int main() { char line[80]; // Max. length=80 Chars scanf("%[^,]s",line); printf("\n%s",line); return(0); }

29.

30.

31.

32.

What will be the output of the following program [NOTE : THE USER INPUT IS :A B C] : int main() { char a,b,c; scanf("%c%c%c",&a,&b,&c); printf("a=%c b=%c c=%c",a,b,c); return(0); } What will be the output of the following program [NOTE : THE USER INPUT IS:5 5.75] : void main() { int i=1; float f=2.25; scanf("%d a %f",&i,&f); printf("%d %.2f",i,f); } What will be the output of the following program [NOTE : THE USER INPUT IS :ABC DEF GHI] : int main() { char a,b,c; scanf("%c %c %c",&a,&b,&c); printf("a=%c b=%c c=%c",a,b,c); return(0); } What will be the output of the following program [NOTE : THE USER INPUT IS:CMeansSea Ocean Vast] : int main() { char a[80],b[80],c[80]; scanf("%1s %5s %3s",a,b,c); printf("%s %s %s",a,b,c); return(0); } What will be the output of the following program [NOTE : THE USER INPUT IS :123456 44 544] :

33.

34.

35.

36.

int main() { int a,b,c; scanf("%1d %2d %3d",&a,&b,&c); printf("Sum=%d",a+b+c); return(0); } 37. What will be the output of the following program : int main() { char line[80]; scanf("%[^1234567890\n]",line); return(0); } What will be the output of the following program : int main() { char line[80]; scanf("%[^*]",line); return(0); }

38.

C TOKENS PREDICTION (BASED ON RULES) 1. Determine which of the following are VALID identifiers. If invalid, state the reason. (a) sample1 (b) 5sample (c) data_7 (d) return (e) #fine (f) variable (g) 91-080-100 (h) name & age (i) _val (j) name_and_age Determine which of the following are VALID character constants. If invalid, state the reason. (a) 'y' (b) '\r' (c) 'Y' (d) '@' (e) '/r' (f) 'word' (g) '\0' (h) '\?' (i) '\065' (j) '\'' (k) ' '

2.

3.

Determine which of the following are VALID string constants. If invalid, state the reason. (a) 'Hi Friends' (b) "abc,def,ghi" (c) "Qualification (d) "4325.76e-8" (e) "Don\'t sleep" (f) "He said, "You\'re great" (g) "" (h) " " (i) "Rs.100/-" Determine which of the following numerical values are valid constants. If a constant is valid, specify whether it is integer or real. Also, specify the base for each valid integer constant. (a) 10,500 (b) 080 (c) 0.007 (d) 5.6e7 (e) 5.6e-7 (f) 0.2e-0.3 (g) 0.2e 0.3 (h) 0xaf9s82 (i) 0XABCDEFL (j) 0369CF (k) 87654321l (l) 87654321 Determine which of the quantity (5 * 100000). (a) 500000 (b) 0.5e6 (f) 500E3 (g) .5E6 (k) All of the above following floating-point constants are VALID for the (c) 5E5 (d) 5e5 (h) 50e4 (i) 50.E+4 (l) None of these (e) 5e+5 (j) 5.0E+5

4.

5.

CHAPTER -4.3 Arithmetic Operators, Relational Operators, Assignment Operators,Logical Operators, Increment And Decrement Operators, Conditional Operator, Bitwise Operators ONE WORD ANSWERS

Q1) How many arithmetic operators exist in C ? Ans: Five. Q2) What are the different arithmetic operators? Ans: The different arithmetic operators are: + (addition), - (subtraction), * (multiplication), / (division), % (modulo division). Q3) What is precedence of an operator? Ans: Precedence of an operators decides the order in which different operators are applied. Q4) What is associativity ? Ans: Associativity decides the order in which operands are associated with operator. Q5) How many types of associativity exist in C ? Ans : Two types. Q6) What are two types of associativity ? Ans : Left to Right & Right to Left. Q7) Which arithmetic operator/s has highest precedence? Ans: * , / and % Q8) Which arithmetic operator/s has lowest precedence? Ans: + and Q9) What is the associativity of arithmetic operators? Ans: Left to Right. Q10) Which operator has highest precedence level in c? Ans: ( ) [] has highest precedence level in c . Q11) What will be the value of x,y,z for a=9,b=12,c=3 (all are declared as float data type) 1. x = a-b/3+c*2-1; 2. y = a-b/(3+c)*(2-1); 3. z = a-(b/(3+c)*2)-1; Ans: 1.x = 10.0000 2.y = 7.0000

3.z = 4.000. Q12) How many relational operators exist in C? Ans: Six Q13) What are the different relational operators? Ans: The different relational operators are: < (is less than), <= (less than or equal to), > (greater than), >= (greater than or equal to), == (equal to), !=(not equal to). Q14) Which relational operators have highest precedence? Ans: >, <, >=, <= Q15) Which relational operator has lowest precedence? Ans: = =, != Q16) What is the associativity of relational operators? Ans: Left to Right. Q17) What are the different assignment operators? Ans: =, +=, -=, *=, /=, %=, &=, ^=, |=, <<=, >>= Q18) What is the associativity of assignment operators? Ans: Right to Left Q19) What will be the values of a, b, c, d (all are integer data types) and a=10,b=3,c=2,d=8 1. a+=1; 2. b-=1; 3. c*=2; 4. d/=4; Ans: a=11, b=2, c=8, d=2. Q20) How many Logical operators exist in C? Ans: Three Q21) What are the different logical operators? Ans: && (LOGICAL AND), || (LOGICAL OR), ! (LOGICAL NOT) Q22) What is the associativity of logical and (&&), logical or (||) ? Ans: Left to Right initially

Q23) What is the associativity of logical not ? Ans: Right to Left Q24) What is the associativity of increment and decrement operators? Ans: Right to Left Q25) What is an increment operator? Ans: The operator which automatically increments the the value by one. Q26) How many types of increment operators exist in C ? Ans: Two types. Q27) What are the two types of increment operators exist in C ? Ans : Post increment and pre increment. Q28) Which is a pre / post increment operator? Ans: ++ Q29) Give an example for usage of pre increment operator Ans: ++a Q30) Give an example for usage of post increment operator Ans: a++ Q31) What is post increment operator? Ans : An operator which increments the value of a variable after the operation Q32) What is pre increment operator? Ans : An operator which increments the value of a variable before the operation. Q33) What is a decrement operator? Ans: The operator which automatically reduce the the value by one. Q34) How many types of decrement operators exist in C ? Ans: Two types. Q35) What are the two types of decrement operators exist in C ? Ans : Post decrement and pre decrement. Q36) Give an example for usage of pre decrement and post decrement operator? Ans: --a & a--;

Q37) What is the value of m and y in the below expression? m = 5; y = ++m; Ans: m=6,y=6. Q38) What is the value of m and y in the below expression? m = 5; y = m++; Ans: y=5, m=6. Q39) Which is a conditional operator? Ans: A ternary operator (? :) is a condiational operator. Which is an alternate for if else statement. Q40) What is the associativity of a conditional operator? Ans: Right to Left Q41) What will be the value of x after evaluating the following expression? a=10; b=15; x= (a>b)?a:b; Ans: 15 Q41) How many bitwise operators exist in C ? Ans: Six. Q42) What are the different Bit wise operators? ans: Bit wise AND(&), bit wise OR(|), bit wise exclusive OR(^), shift left(<<), shift right (>>), and Ones compelent ( ~) are called Bit wise operators. Q43) What is the associativity of bitwise operators? Ans: Left to Right.

MULTIPLE CHOICE QUESTIONS:


1. What will be output of the following c program? #include<stdio.h> int main() { int goto=5; printf("%d",goto); return 0;

} a. goto

b.5

c.go to 5

d.compilation error

2. What will be output of the following c program? #include<stdio.h> int main() { long int 1a=5l; printf("%ld",1a); return 0; } a. 51 b. 510 c. 58 d.60 3. What will be output of the following c program? #include<stdio.h> int main() { int _=5; int __=10; int ___; ___=_+__; printf("%i",___); return 0; } a. 51 b. 61 c. 15 4.What will be output of the following c program? #include<stdio.h> int main() { int max-val=100; int min-val=10; int avg-val; avg-val = max-val + min-val / 2; printf("%d",avg-val); return 0; } a.10 b.15 c. 105 5. What will be output of the following c program? #include<stdio.h> int main() {

d.151

d.150

int class=150, public=25, private=30; class = class >> private - public; printf("%d",class); return 0; } a.2 b. 1 c.45 d.257

OUTPUT PREDICTION 1. What will be output of the following program? #include<stdio.h> int main() { int i=1; i=2+2*i++; printf("%d",i); return 0; } 2. What will be output of the following program? #include<stdio.h> int main() { int a=2,b=7,c=10; c=a==b; printf("%d",c); return 0; } 3. What will be output of the following program? #include<stdio.h> void main() { int x; x=10,20,30; printf("%d",x); return 0; } 4. What will be output of the following program? #include<stdio.h>

int main() { int a; a=015 + 0x71 +5; printf("%d",a); return 0; } 5. What will be output of the following program? #include<stdio.h> int main() { printf("%d %d %d",sizeof(3.14),sizeof(3.14f),sizeof(3.14L)); return 0; } 6. What will be output of the following program? #include<stdio.h> int main() { int x=100,y=20,z=5; printf("%d %d %d"); return 0; } 7. What will be output of the following program? #include<stdio.h> int main() { int a=2; a=a++ + ~++a; printf("%d",a); return 0; } 8. What will be output of the following program? #include<stdio.h> int main() { int a; a=sizeof(!5.6); printf("%d",a);

return 0; } 9. What will be output of the following program? #include<stdio.h> int main() { float a; (int)a= 45; printf("%d,a); return 0; } 10. What will be output of the following program? #include<stdio.h> int main() { int i=5; int a=++i + ++i + ++i; printf("%d",a); return 0; }

ASSIGNMENT Q. Q. Q. Q. Q. Q. Q. Q. Write a C program to illustrate the use of arithmatic operators Write a C program to illustrate the use of unary operators Write a C program to illustrate the usage type cast operators Write a C program to evaluate the polynomial 3x^3-5x^2+6=0 for x=2.55 Write a C program to evaluate the following expression (3.31x10^-8x2.01x10^-7)/(7.16x10^-6=2.01x10^-8) a=1.82,b=3.18,c=3.37,d=4.18 Write a C program to evaluate the expression [8.8(a+b)2/c-0.5+29(c+d)]/[(a-b)/d] Write a C program to evaluate the expression [7.7b(bc+a)/d-0.8+2b]/[d+a/c] If a five digit number is input through keyboard, write a c program to calculate sum of digits

CHAPTER 4.4 Decision making : The If Statement , The If Else Construct, Nested If Statements, Switch Statement, The Conditional Operator The IF Statement The if statement is a decision making statement and used to control the flow of execution of statements. It's general syntax is if(test expression) { executable part; } Q1. When if block is executed? Ans: Only when the test expression is true. Q2. What is the other name of if statements? Ans: Decission control statement. The If Else Construct: The if else statement is an extension of the simple if statement .It's general syntax is if(test expression) { true block statements; } else { false block statements; }

if the test expression is true,then the true block statements are executed otherwise the flase block statements are executed. Q3. When will be the else part be executed? Ans: Only when ifs text expression is false. Nested If Statements: When a series of decisions are involved we may have to use more than one if statements. Then we use nested if statements. Its general syntax is if(test condition 1) { if(test condition 2) { statements.. } } Q4. What is nested if statement ? Ans. If statement within an if statement is known as nested if statement. Q5. When will be the nested if be executed? Ans: Nested ifs are executed only when all the testconditions are satisfied. Switch Statement: The switch statement test the value of a given expression against a list of case values. When a match is found a block of statements associated with the case is executed, its general syntax is switch(expression) { case value-1: block-1; break; case value-2: block-2; break; .... default: default -block; break; } Q6. When the default statements are executed? Ans: When the entered value is not among the switch case values then default statements are executed.

Q7. Which type of data is allowed in switch case? Ans: int or char constant. The Conditional Operator The ternary operator( ?: ) is called as conditional operator and it works like if else statement. expression1? expression2 : expression3 ; Q8. How many operands required for conditional operator? Ans: Three operands .

MULTIPLE CHOICE QUESTIONS: 1) What will be the output of the following program : void main() { int i=1; for (; i<4; i++); printf("%d\n",i); } a.No Output b. 1 c. 4 d. None of these 2 3

2)

What will be the output of the following program : void main() { int a,b; for (a=0; a<10; a++); for (b=25; b>9; b-=3); printf("%d %d",a,b); } a. Compile-Time error b. 10 9 c.10 7 d. None of these

3)What will be the output of the following program : void main { float i; for (i=0.1; i<0.4; i+=0.1) printf("%.1f",i); } a. 0.10.20.3 b. Compile-Time Error c. Run-Time Error d. No Output 4) What will be the output of the following program : void main() { int i; for (i=-10; !i; i++); printf("%d",-i); } b. Compile-Time Error c.10 d. No Output What will be the output of the following program : void main() { int i=5; do; printf("%d",i--); while (i>0); } b. 54321 c. Compile-Time Error d. None of these

a. 0 5)

a. 5

6) What will be the output of the following program : void main() { int i; for (i=2,i+=2; i<=9; i+=2) printf("%d",i); } a. Compile-Time error b. 2468 c. 468 d. None of these 7) What will be the output of the following program : void main() { int i=3;

for (i--; i<7; i=7) printf("%d",i++); } a. No Output b. 3456 c. 23456 d. None of these.

8) What will be the output of the following program : void main() { int i; for (i=5; --i;) printf("%d",i); } a. No Output b. 54321 c. 4321 9) What will be the output of the following program : void main() { for (;printf("");); } a. Compile-Time error b. Executes ONLY once c. Executes INFINITELY d. None of these

d. None of these

10)What will be the output of the following program : void main() { int i; for (;(i=4)?(i-4):i++;) printf("%d",i); } a. Compile-Time error b. 4 c . Infinite Loop d.No Output

Vous aimerez peut-être aussi