JAYASHREE ORACLE CERTIFIED JAIN UNIVERSITY

Tuesday, September 28, 2010

BLOGS for Diffrent Subjects

http://jayashree-dbms.blogspot.com/
http://jayashree-sqlplsql.blogspot.com/
http://bca-3sem-vb.blogspot.com/
http://bca-3sem-cpp.blogspot.com/
http://bca-3sem-se.blogspot.com/

Friday, September 24, 2010

C Q Bank

C Skills Written Test Questions

1. find(int x,int y)
{ return ((xcall find(a,find(a,b)) use to find
(a) maximum of a,b
(b) minimum of a,b
(c) positive difference of a,b
(d) sum of a,b

2. integer needs 2bytes , maximum value of an unsigned integer is
(a) { 2 power 16 } -1
(b) {2 power 15}-1
(c) {2 power16}
(d) {2 power 15}

3.y is of integer type then expression
3*(y-8)/9 and (y-8)/9*3 yields same value if
(a)must yields same value
(b)must yields different value
(c)may or may not yields same value
(d) none of the above

4. 5-2-3*5-2 will give 18 if
(a)- is left associative,* has precedence over -
(b) - is right associative,* has precedence over -
(c) - is right associative,- has precedence over *
(d)- is left associative,- has precedence over *

5. printf("%f", 9/5);
prints
(a) 1.8,
(b) 1.0,
(c) 2.0,
(d) none
.
6. if (a=7)
printf(" a is 7 ");
else
printf("a is not 7");
prints
(a) a is 7,
(b) a is not 7,
(c) nothing,
(d) garbage.

7. if (a>b)
if(b>c)
s1;
else s2;
s2 will be executed if
(a) a<= b,
(b) b>c,
(c) b<=c and a<=b,
(d) a>b and b<=c.

8. main()
{
inc(); ,inc(); , inc();
}
inc()
{ static int x;
printf("%d", ++x);
}
prints
(a) 012,
(b) 123,
(c) 3 consecutive unappreciable numbers
(d) 111.

9.preprocessing is done

(a) either before or at beginning of compilation process
(b) after compilation before execution
(c) after loading
(d) none of the above.

10. printf("%d", sizeof(""));
prints
(a) error
(b)0
(c) garbage
(d) 1.

11.main()
{
int a=5,b=2;
printf("%d", a+++b);
}

(a) results in syntax,
(b) print 7,
(c) print 8,
(d) none,

12. process by which one bit pattern in to another by bit wise operation is
(a) masking,
(b) pruning,
(c) biting,
(d) chopping,

13.value of automatic variable that is declared but not initialized
will be
(a) 0,
(b) -1,
(c) unpredictable,
(d) none,

14. int v=3, *pv=&v;
printf(" %d %d ", v,*pv);
output will be
(a) error
(b) 3 address of v,
(c) 3 3
(d) none.

15. declaration
enum cities{bethlehem,jericho,nazareth=1,jerusalem}
assian value 1 to
(a) bethlehem
(b) nazareth
(c)bethlehem & nazareth
(d)jericho & nazareth

16. #include
#include
void main()
{
char buffer[82]={80};
char *result;
printf( "input line of text, followed by carriage return :n");
result = cgets(buffer);
printf("text=%sn",result);
}
(a) printf("length=%d",buffer[1]);
(b) printf("length=%d",buffer[0]);
(c) printf("length=%d",buffer[81]);
(d) printf("length=%d",buffer[2]);

17. consider scanf and sscanf function , which is true

(a) no standard function called sscanf
(b) sscanf(s,...) is equivalent to scanf(...) except that
input charecter are taken from string s.
(c) sscanf is equivalent to scanf.
(d) none of above.

18. #include
main()
{
char line[80];
scanf("%[^n]",line);
printf("%s",line);
}
what scanf do ?
(a) compilation error . Illegal format string.
(b) terminates reading input into variable line.
(c) and (d) other two options.

19. Problem was big so i couldn't remember . Simple one.

20 . ceil(-2.8) ?
(a) 0
(b) -3.0
(c) -2.0
(d) 2

21. for( p=head; p!=null; p= p -> next)
free(p);

(a) program run smooth.
(b) Compilation error.
(c) Run time error.
(d) None of above.

22. int x[3][4] ={
{1,2,3},
{4,5,6},
{7,8,9}
}
(a) x[2][1] = x[2][2] =x[2][3] = 0
(b) value in fourth column is zero
(c) value in last row is zero
(d) none of above.

24. main ()
{
printf("%u" , main());
}
(a) print garbage.
(b) Execution error
(c) printing of starting address of function main.
(d) Infinite loop.

25 . int a, *b = &a, **c =&b;
....
....
.....
a=4;
** c= 5;

(a) doesn't change value of a
(b) assign address of c to a.
(c) assign value of b to a.
(d) assign 5 to a.

28 . answer: swapping of values .

30 . i =5;
i= (++i)/(i++);
printf( "%d" , i);
prints ,
(a) 2
(b) 5
(c) 1
(d) 6

C Q Bank

Subject: Computer Concepts & C programming
Sub Code: CCP/23

1. Write the algorithm for computing the biggest of 3 given numbers also write the flow chart.
2. Evaluate each of the following expr independent of eachother. The declaration and initialiasation statement is int i=3,j=4,k=2;
i) i+ + - j -- ii)++k % --j
iii) j+1/i-1 iv) j++/i--
3. In the following expr write the hierarchy of computation and also mention the type of the operator
A*x*x+b*x-c/d>=x&&x!=15.0
4. List the different types of constants used in C. Give 2 examples in each type.
5. With a example explain scanf(() and printf() statements.
6. int a,b;
a=11;b=6;
Give the results of
(i) a &b (ii) a: b (iii) a ^b (iv) a>>2 (v)~b
7. List out fundamental data types in C.
8. What is flow chart? List out symbols used in writing flowchart.
9. Explain the use of bitwise operators in C with examples.
10. Explain with example an algorithm and flowchart.
11. Distinguish between variables and keywords with example.
12. Explain different unary operators in C.
13. Explain relational operators in C.
14. With an example getch() and putchar() functions.
15. Explain briefly printf() with format specifiers.
16. Mention different primitive data types and memory required for them.
17. Mention different operators used in C with examples.
18. Write a program to find the squares and cubes of a 2 digit odd number.
19. Write a program to compute the area of an isosceles triangle.
20. Explain the following operators with eqution:
i) Logical operators
ii ) Relational operators
iii) conditional operators
21. Write the expr in C lang and evaluate the arithmetic expr.
a=4,b=2,c=4
b(a+b)²/a²(a-b)
2ab/a+b.c
22. Give the basic structure of a C program and explain with an example to find the area and perimeter of a circle of given radius ‘r’.Give the purpose of each line in the program.
23. What is a variable? How are keywords different from them?
24. Explain the following:
i) Conditional operator
ii) Comma operator
iii) size of operator
25. Identify the syntax errors in the following program
main {}
{
float X;
X=25;
Y=Exp(x);
/** printing section**/
Print(x,y)
}
26. Give the syntax and explain the semantics of formatted i/p and o/p statements.
27. What are bitwise operators available in C?
28. What is a conditional operator? Execute the statement:
y=(x>z)? (2*x+5) :( 1.5*x+3);
29. Write a program segment that will read the value of a x & evaluate the following functions.
1 for x>0
Y= 0 for x=0
-1 for x<0
Using (i) nested if statement (ii) Else if statement (iii) Conditional operator
30. Given 3 sides of a triangle, write a c program to classify the triangle as equilateral, isosceles and scalene.
31. Explain the syntax of switch statement with an example.
32. Explain while loop structure with an example write the flow chart also
33. Write a c program to solve a quadratic equation using switch statement.
34. Using array declaration for Fibonacci series, write a c program to generate first nterms.
35. Write a program to read ten integers from the keyboards and print the sum of evenand odd numbers.
36. Distinguish between while and do while
37. What do you mean by looping? give the syntax for looping statements in c.
38. Write a program to check whether the given number is prime or not. Print the suitable messages.
39. Write a c program to check whether a given 5 digit number is palindrome or not
40. List the different types of control statements explain the types of if statement gives one example for each.
41. Write a program to convert a given decimal numbers into its binary equivalent.
42. Give the syntax of a switch statement and also write an equivalent ladder if statement.
43. Write a program using switch statement to grade the students marks as A=80 andabove=70 and above=60 and above D=40 and above and the rest below 40 as E grade.
44. Write a program to evaluate the following series.
f(x)=x-x³/3! + x/5!-x/7!......................unto given numbers of terms.
45. Write a program to find the number and sum of all integers from 100to 200 and divisible by 7.
46. Write a program segment that will read the value of x and evaluate following function:
1 for x>0
y= 0 for x=0
-1 for x<0
using i) nested if statements ii)else if statements.
47. What is an array? How are they declared in ‘C’? What are the rules to be followedwhile using arrays?
48. a and b are two integers arrays each with n elements. Write a program to find the array c such that
c[i]=a[i]+b[n-1-i]
49. Given two sets A and B of integers, write a program to read them. Determineits UNION and INTERSECTION and print the resultant sets.
50. Write a function to concatenate two strings, write a program to read three Strings anduse the function to concatenate them and print it.
51. Give any five string manipulation library functions, with an example each.
52. You are given sufficient number of 5 paise,10 paise,20 paise,25 paise and 50 paise denominations. Given a value of R rupees and P paise,write a C program to determine the minimum number of coins to get the required value. Use any looping construct to implement the program.
53. Explain dot matrix printer.
54. Explain the structure of floppy disc
55. Explain the structure of hard disc. Compare floppy disc and hard disc.
56. Write a note on CD –ROM
57. Discuss the advantages and disadvantages of machine level language.
58. Discuss the advantages of High level language

C Progrramming Blue Print

C PRogramming Model Question Paper

Programming in C

Part A: Answer any 10 questions 2 x 10 = 20

1. What is an Algorithm?
2. What are the advantages of high level languages over machine language?
3. Give any two differences between compilers & interpreters.
4. Give any 2 differences between while statement and a Do- while statement in C?
5. What is an array? Define an array to store marks of 30 students in 3 subjects.
6. Write C statement to find maximum of two numbers using ternary operator.
7. What are preprocessor directives?
8. What are bitwise operators available in C?
9. Give any 2 two differences between Structures & Union.
10. What does a storage class mean? Mention different storage classes available in C.
11. List any 5 Date and time functions.
12. What are enumerated data types? Give an example.
13. What is recursion? What are its advantages?
14. Give any two differences between call by value and call by reference?
15. How do you pass parameters to main() function?


Part B: Answer any 6 questions 5 x 6 = 30

1. What are keywords? List the rules for naming a variable in C?
2. Write a C Program to print the following output using nested loops.
*
* *
* * *
* * * * *
* * * * * *
3. Draw a flowchart to solve a quadratic equation.
4. Write an algorithm to find the sum of numbers from 1 to N.
5. Write a program to read data from keyboard, write it to a file called INPUT, and read the same data from the INPUT file and display it on the screen.
6. Write a function to exchange the values of two variables, say x and y.
7. Demonstrate the usage of a switch statement with an example.
8. Explain the use of printf and scanf functions with all formatting facilities.


Part C: Answer any 3 questions 10 x 3 = 30

1. Write a program to read a line of text and output the number of words and characters in it.
2. Write a program to multiply 2 Matrices.
3. Write a program using pointers to read an array of integers and print its elements in reverse order.

4. Explain the different kinds of loops available in C with examples.
5. Define a structure data type called TimeStruct containing 3 members called hour, minute and second. Develop a program that would assign values to the individual members and display the time in the form 16:40:30



* * * * *

TRYY!!!!!!!!!!!!!!!! :)

Section 1: Declarations and Initializations [a]
1.1: How do you decide which integer type to use?
Use ``short'' when you need to avoid values over 32,767, ``int'' when you want to store integers, ``long'' for long numbers (more than 6 digits), and ``float'' for numbers over 4 billion.
1.2: What should the 64-bit type on new, 64-bit machines be?
int.
1.3: If I write the code int i, j; can I assume that (&i + 1) == &j?
Only sometimes. It's not portable, because in EBCDIC, i and j are not adjacent. [a]
1.4: What's the best way to declare and define global variables?
In headers; this way, you can get link errors when you include the same header twice. Generally, you will have to define a variable everywhere you want to use it, and then declare it someplace so you know what it is. [a]
1.5: What does extern mean in a function declaration?
It refers to a variable which is not actually in your program. For instance,
main() {
extern int bar;
printf("%d\n", bar);
return 0;
}
will compile without errors because bar is declared as being external. (It won't run, though, because you never assign bar a value.) [a]
1.6: I finally figured out the syntax for declaring pointers to functions, but now how do I initialize one?
With the assignment operator. You were perhaps expecting a screwdriver?
Section 2: Structures, Unions, and Enumerations [a]
2.1: What is the difference between an enum and a series of preprocessor #defines?
The enum doesn't require the preprocessor.
2.2: I heard that structures could be assigned to variables and passed to and from functions, but K&R I says not.
K&R I was wrong; they hadn't actually learned C very well before writing the book. Later, Ritchie got a job at Bell Labs, and worked closely with the authors of C, allowing the 2nd edition of the book to be much more accurate. (Kernighan already worked at Bell Labs, as a video game developer.) [a]
2.3: How does struct passing and returning work?
The structures are put into the low part of the VGA card's VRAM. They are then removed before the next video update. This is why struct passing was not supported for a long time; VGA cards were prohibitively expensive.
If you try to pass very large structures on the stack, you may see odd screen graphics. [a]
2.4: Why can't you compare structs?
Compare them to what? A summer's day?
2.5: How can I read/write structs from/to data files?
Loop with putchar. Be careful; if your machine uses signed chars by default, all of the sign bits in your structure elements will be reversed. [a]
2.6: How can I determine the byte offset of a field within a structure?
It's generally 4 times the number of members of the structure. It may be more or less on some machines. [a]
2.7: How can I access structure fields by name at run time?
foo."name" should work. You may need to overload the . operator, which, in turn, may overload your C compiler.
2.8: Why does sizeof report a larger size than I expect for a structure type, as if there was padding at the end?
Because there's padding at the end. Duh.
2.9: My compiler is leaving holes in structures, which is wasting space and preventing ``binary'' I/O to external data files. Can I turn off the padding, or otherwise control the alignment of structs?
Sure. What you do to eliminate the padding in structures is use unions; for intance,
struct foo {
char c;
long l;
char d;
char e;
char f;
};
may cause struct foo to be padded to 12 bytes, rather than the correct size of 8. Try
union foo {
double _d;
char c, d, e, f;
long l;
};
which will be 8 bytes. (The double is for alignment.) [a]
2.10: Can I initialize unions?
Depends. They may go on strike when provoked. Luckily, if your program involves air traffic control, the ISO standard guarantees that Ronald Reagan will fire any unions that go on strike, and replace them with structs, which should be close enough. [a]
2.11: How can I pass constant values to routines which accept struct arguments?
Try foo((struct foo) 3). [a]
Section 3: Expressions [a]
3.1: Why doesn't the code a[i] = i++; work?
You didn't declare either i or a.
3.2: Under my compiler, the code
int i = 7;
printf("%d\n", i++ * i++);
prints 49. Regardless of the order of evaluation, shouldn't it print 56?
No. The only logical answer would be 81 - two postfix ++'s are automatically converted to prefix.
3.3: I've experimented with the code
int i = 2;
i = i++;
on several compilers. Some gave i the value 2, some gave 3, but one gave 4. I know the behavior is undefined, but how could it give 4?
Because i is 2, the loop is executed twice.
3.4: People keep saying the behavior is undefined, but I just tried it on an ANSI-conforming compiler, and got the results I expected.
They were probably wrong. Flame them mercilessly. Be sure before you do that your compiler is really ANSI conforming, though. If it turns out you were wrong, they get a legal claim on your first-born.
3.5: Can I use explicit parentheses to force the order of evaluation I want? Even if I don't, doesn't precedence dictate it?
No. To force order of evaluation, you must threaten it. Take the comma operator hostage. Using it, you can force the other operators to do what you want. [a]
3.6: But what about the &&, ||, and comma operators? I see code like ``if((c = getchar()) == EOF || c == '\n')'' ...
As noted, once you've captured the comma operator, the others become docile.
3.7: If I'm not using the value of the expression, should I use i++ or ++i to increment a variable?
++i. Only losers and idiots use i++. This is different if your native language would idiomatically use ``i increment'', but in English and related languages, you must use ++i. Note that a modern program must use both, dependent on the current locale.
3.8: Why is i = ++i undefined?
Because it is unclear whether it is shorthand for i = 42; or i = (char *) "forty two";.
Given the ambiguity, the standards committee decided to leave it undefined.
Section 4: Null Statements [a]
4.1: What is this infamous null statement, anyway?
A null statement is an expression statement consisting solely of the terminating semicolon. The optional expression is dropped. It can be distinguished from any other statement by byte count or study of side-effects.
4.2: How do I ``get'' a null statement in my programs?
In ANSI C, there are six types of statements; labeled statements, compound statements, expression-statements, selection statements, iteration statements, and jump statements. All of them, except the jump and expression statments, are defined in terms of optional preceeding text, and other statements. The jump statements are never null statements. An expression statement is considered to be ``a null statement'' if the optional expression part of it has been left out. A null statement can appear on its own, or (most frequently) as the statement body of an iteration statement. These two null statements are equivalent, though neither of them is equivalent to any non-null statement. [*]
You may accidentally get a null statement by deleting the body of a non-null statement.
[*] Actually, they are functionally equivalent to a large set of non-null statements, namely, those with no side-effects. However, the FDA has yet to approve any such, as their lack of side effects is conjectured, and not clinically proven. This applies only to the ANSI standard, and not the ISO standard, as the FDA has no jurisdiction outside the U.S. [a]
4.3: Is there more than one null statement?
Sort of. You can use ``;'', ``0;'', or ``1;'' - they will all act like a null statement. Only the first is a ``true'' null statement (all bits zero). They are basically equivalent. Note that (void *) 0; is a null statement of type pointer to void, for instance. [a]
4.4: But I thought { } was a null statement!
No. { statement-list[opt] } is a compound statement. An empty block is not the same as a null statement, however, although it can be used in many of the same places. It's really a null block. (You can convert it with a cast, but it's not directly compatible. For instance, you can't use a null block as one of the controlling statements of a for loop.)
4.5: I use the statement #define NULLSTMT(F) (F) ; to allow me to cast a null statement to an appropriate type.
This trick, though popular in some circles, does not buy much. The resulting code is invalid, and will not compile. This (in the author's opinion) outweighs any arguable type consistency. It may be more common in industrial code. If it becomes common practice, C++ will probably legalize it. [a]
4.6: I use the statement #define NULLSTMT(F) (F) 0; to allow me to cast a null statement to an appropriate type.
This trick will likely work, but think: what does it really buy you? Mostly, it will indicate to even the most casual observer that you are shakey on the concept of null statements, making it harder for them to check your code.
4.7: But wouldn't it be better to use ; (rather than 0;) in case the value of 0 changes, perhaps on a machine with nonzero no-op instructions?
No. The '0' of '0;' is not evaluated as an instruction, rather, it is just ignored. The only reason to use '0;' instead of ';' is to help keep 1-heavy code properly balanced (in C, which uses binary representations for numbers, it is possible for code to become unbalanced; an unbalanced binary tree is a common source of poor performance.
4.8: Is a null statement a null pointer?
No. A null pointer is a pointer where all of the address bits are zero (no matter what the segment bits are), and can be obtained by typing '(char *) (int) 0'. A null statement is not a pointer to anything. They are not interchangeable, although you can combine them to get an effectively-null statement, such as NULL;. This does not buy you anything. [a]
4.9: I'm still confused. I just can't understand all this null statement stuff.
Follow these two simple rules:
1. When you don't want to do anything in source code, don't write it.
2. If you need a null statement to round out an expression, use an unadorned ; to provide it.
3. Send large donations, checks, and money orders to the author of the FAQ, or the moderator of the group, whichever you prefer. Then, cross the top question off the FAQ, answer the question at the bottom, and mail it to three people. Within two weeks, you will receive 729 answers to various questions! Do not break the chain; Emily Postnews broke the chain, and now no one listens to her. [a]
Section 5: Arrays and Pointers
5.1: I had the definition char a[6] in one source file, and in another I declared extern char a[]. Why did it work?
The declaration extern char a[] simply matches the actual definition. The type ``array-of-type-T'' is the same as ``array-of-type-T.'' Go ahead and use extern char a[]. (For greater portability, use it in both files, not only in one of them.) [a]
5.2: But I heard that char a[] was different from char a[6].
This is true. However, the declaration a[] is compatible with the definition a[6].
5.3: So what is meant by the ``equivalence of pointers and arrays'' in C?
Very little.
5.4: Then why are array and pointer declarations interchangeable as function formal parameters?
Classism. We consider arrays ``second class objects''. They don't vote, and they get treated as pointers. Additionally, they're merely objects, not citizens. Marx wrote about this a lot. [a]
5.5: Why doesn't sizeof properly report the size of an array which is a parameter to a function?
Part of the ANSI conspiracy to restrict people to passing pointers; this was undertaken after the first discovery that passing large arrays recursively could cause crashes. Since then, with the passing of MS-DOS, it has become a non-issue; since all serious machines have virtual memory, you can pass as much data as you want on the stack without detectable problems. [a]
5.6: Someone explained to me that arrays were really just constant pointers.
Cool. Someone I know says he saw Elvis in a local bar. [a]
5.7: Practically speaking, what is the difference between arrays and pointers?
About the difference between alcohol and marijuana; they have different characteristics, and that's not a problem if you don't mix them too carelessly.
5.8: I came across some ``joke'' code containing the ``expression'' 5["abcdef"]. How can this be legal C?
It was added to allow people to avoid the character constant 'f' which may not be available on some systems. (Actually, it's a side-effect of the equivalence of arrays and pointers.) [a]
5.9: How would I initialize an entire array from standard input?
You have to use a loop. For instance, the following code reads the numbers zero through 99 into the array a.
for (i = 0; i < 100; ++i)
a[i] = (scanf, ("%d", i));
Make sure to include , or this may not work. [a]
Section 6: Memory Allocation
6.1: Why doesn't this fragment work?
char *answer
printf("Type something:\n");
gets(answer);
printf("You typed \"%s\"\n", answer);
The semicolon after ``answer'' is missing. [a]
Section 12: Library Subroutines
12.1: How can I convert numbers to strings (the opposite of atoi)? Is there an itoa function?
There's frequently an itoa function. Better yet, write your own; it'll be good practice. On some implementations, (char *) x; will convert x to a string.
12.2: How can I get the current date or time of day in a C program?
fprintf(stderr, "please enter the current time and date..."); fflush(stderr); gets(stdin);
12.3: I need a random number generator.
Count errors in Herbert Schildt's C books. No one has detected any consistent pattern.
12.4: How can I get random integers in a certain range?
random(n) returns random numbers between n and INT_MAX.
12.5: Each time I run my program, I get the same sequence of numbers back from rand().
This is so your results will be reproducible.
12.6: I need a random true/false value, so I'm taking rand() % 2, but it's just alternating 0, 1, 0, 1, 0...
That seems pretty random to me.
12.7: I need some code to do regular expression matching.
So do I. Let me know if you find some.
12.8: I read through the standard library, but there's no function to multiply two floating point numbers! Help!
Many C compilers offer an extension ``mult'' to do just this. If your compiler doesn't, just hang tight; ANSI is likely to add it in the next revision.
For now, you can try
float mult(float m, n)
{
float i = 0, j = 0;
for (i = 0; i < n; ++i)
j += m;
return j;
}
which is fine as long as n is an integer.
12.9: How do I get past the snake?
Release the bird. You will have to drop the rod to get the bird in the cage. [a]
Section 13: Floating Point
13.1: My floating-point calculations are acting strangely and giving me different answers on different machines.
One of the machines is probably a Pentium. Scrap it and get a real machine. [a]
13.2: I'm trying to do some simple trig, and I am #including , but I keep getting ``undefined: _sin'' compilation errors.
You forgot to define the sin() function. Most math texts should cover it in some detail. The easiest way to fix this should be:
double sin(double x) {
return sqrt(1 - cos(x) * cos(x));
}
Warning: You must not declare this function as ``extern'', or you will still have link problems.
13.3: Why doesn't C have an exponentiation operator?
It does. It looks like the multiplication operator, but you use it more. For instance, the C way of expressing ``x squared'' is ``x*x''. ``x cubed'' would be ``x*x*x''. Easy, isn't it?
13.4: How do I round numbers?
Multiply by 10. Numerical Recipies in C has a section on this, but there's reputedly a bug in their algorithm.
13.5: How do I test for IEEE NaN and other special values?
Using an electron microscope; the patterns are obvious once you know them.
13.6: I'm having trouble with a Turbo C program which crashes and says something like ``floating point formats not linked.''
Turbo C is notoriously buggy. Get a compiler with floating point support.
13.7: What is so ``unsafe'' about floating point?
Have you tried EXAMINE STICK? The stick has a sharp point, which punctures the raft, which no longer floats. Don't bring the stick into the raft with you.
13.8: Which is larger, ``2'' or ``2.0''?
Numerical Recipes in C has a function for comparing two values to see which is greater. It may have a slight bug, where it would report incorrect results if the numbers differ by less than FLOAT_MAX / INT_MAX.
13.9: When I try to compile the following code, I get the error ``invalid use of floating point'', what does this mean?

x=663608941*y%pow(2,32);
Remember that * is the indirection operator, as well as the multiplication operator; try putting spaces before and after the ``*'' so the compiler knows what you mean. Do the same with the % operator.
13.10: How can I copy a float into a string?
strcpy(string_var, float_var);
13.11: What are float variables, anyway?
The term ``float variable'' is actually redundant; they are simply variables whose value can ``float'' during execution. For instance:
float f, g = 3;
f = g; /* f ``floats'' to g */
Easy!
What will be output ?
(1) void main()
{
clrscr();
printf("%d",sizeof(3.8));
getch();
}
output: 8
Explanation: 3.8f is float constant, 3.8 is double constant and 3.8L is long double constant .Here are finding size of double constantan which is 8.
For more detail click here (data type)
(2) What will be output ?
void main()
{
char *str1="powla";
char *str2="er";
clrscr();
printf("%s\b\b%s",str1,str2);
getch();
}
output: power
Explanation: \b escape sequence back the cursor one position left .We are using two /b so after writing str1 cursor is at the position of l of powal .So when it write er it will override the la so output will be power.
(3)What will be output ?
void main()
{
int a=270;
char *p;
p=(char *)&a;
clrscr();
printf("%d",*p);
getch();
}
output: 16
(4)What is missing statement of in the following program ?
Void main()
{
int sort(int,int);
int I;
i=sort(5,6);
}
Int sort(int a,int b)
{
int c;
c=a;
a=b;
b=c;
return a;
}
Ans: Function sort returning a value but we are not using return value so there is weastge of two byte memory. So missing statement is ,there should statement which uses the return value.
(5)Write following in term of if and else :
void main()
{
int a=1,b=2,c=3;
clrscr();
if(a==5&&b==6&&c==7)
printf("india");
else
printf("pak");
getch();
}
Ans:

void main()
{
int a=1,b=2,c=3;
clrscr();
if(a==1)
{
if(b==2)
{
if(c==3)
{
printf("india");
}
else
{
printf("pak");
}}
else
{
printf("pak");
} }
else
{
printf("pak");
}
getch();
}
(q)
Give the memory representation of

Struct xxx
{
char a;
int b;
char c;
};
Ans: Memory representation :




More detail click here (union)
(q) Write the following program in term of switch and case ?
void main()
{
int a=3;
if(x>2)
{
printf(“INDIA IS BEST”);
}
else
{
printf(“PAK IS BEST”);
}

}
Ans: if condition always return two value.
1 if condition is true.
0 if condition is false.
So program is
void main()
{
int x=3;
switch(x>2)
{
case 0:printf("India is best");
break;
case 1:printf("Pak is best");
}
getch();
}

C for Swimmers

C For Swimmers
______________

If u don't know how to swim, learn it now. Otherwise participate in the competition.

___________________________________________________________________________

Topic : C Fundamentals
Data Types, Constants & Variables (First 5 queries, Ref: PROGRAMMING WITH C - Schaum's Outline Series)
Playing with scanf function
Operators & Expressions

*************************************************************************************************
* NOTE : All the programs are tested under Turbo C/C++ compilers. *
* It is assumed that, *
* *=> Programs run under DOS environment, *
* *=> The underlying machine is an x86 system, *
* *=> Necessary header files are included. *
* *=> Program is compiled using Turbo C/C++ compiler. *
* The program output may depend on the information based on this assumptions. *
* (For example sizeof(int) = 2 bytes may be assumed). *
*************************************************************************************************


[Q001]. 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
Ans. (a) VALID
(b) Invalid, since an identifier must begin with a letter or an underscore
(c) VALID
(d) Invalid, since return is a reserved word
(e) Invalid, since an identifier must begin with a letter or an underscore
(f) VALID
(g) Invalid, since an identifier must begin with a letter or an underscore
(h) Invalid, since blank spaces are not allowed
(i) VALID
(j) VALID
_________________________________________________________________________________________________

[Q002]. 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) ' '
Ans. (a) VALID
(b) VALID
(c) VALID
(d) VALID
(e) Invalid, since escape sequences must be written with a backward slash (i.e. \)
(f) Invalid, since a character constant cannot consist of multiple characters
(g) VALID (null-character escape sequence)
(h) VALID
(i) VALID (Octal escape sequence)
(j) VALID
(k) VALID
_________________________________________________________________________________________________

[Q003]. 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/-"
Ans. (a) Invalid, since a string constant must be enclosed in double quotation marks
(b) VALID
(c) Invalid, since trailing quotation mark is missing
(d) VALID
(e) VALID (single-quote escape sequence)
(f) Invalid, since the quotation marks and (optionally) apostrophe within the string
cannot be expressed without the escape sequences.
(g) VALID
(h) VALID
(i) VALID
_________________________________________________________________________________________________

[Q004]. 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
Ans. (a) Invalid, since illegal character(,)
(b) VALID
(c) VALID
(d) VALID
(e) VALID
(f) VALID
(g) Invalid, since illegal character(blank space)
(h) Invalid, since illegal character(s)
(i) VALID
(j) Invalid, since illegal characters (9, C, F), if intended as an octal constant.
(k) VALID
(l) VALID
_________________________________________________________________________________________________

[Q005]. Determine which of the following floating-point constants are VALID for the quantity (5 * 100000).
(a) 500000 (b) 0.5e6 (c) 5E5 (d) 5e5 (e) 5e+5
(f) 500E3 (g) .5E6 (h) 50e4 (i) 50.E+4 (j) 5.0E+5
(k) All of the above (l) None of these
Ans. (k)
_________________________________________________________________________________________________

[Q006]. What will be the output of the following program :
void main()
{
printf("%f",123.);
}
(a)123 (b)Compile-Time Error (c)123.00 (d)123.000000
Ans. (d)
_________________________________________________________________________________________________

[Q007]. What will be the output of the following program :
void main()
{
printf("%d",sizeof(integer));
}
(a)2 (b)Compile-Time Error (c)4 (d)None of these
Ans. (b) since there is no such data type called 'integer'.
_________________________________________________________________________________________________

[Q008]. What will be the output of the following program :
void main()
{
char str[]="C For Swimmers";
printf("%d",sizeof str);
}
(a)14 (b)Compile-Time Error (c)15 (d)None of these
Ans. (a)
_________________________________________________________________________________________________

[Q009]. What will be the output of the following program :
void main()
{
char str[]="C For Swimmers";
printf("%d",++(sizeof(str)));
}
(a)14 (b)Compile-Time Error (c)15 (d)None of these
Ans. (b)
_________________________________________________________________________________________________

[Q010]. What will be the output of the following program :
void main()
{
char str[]="C For Swimmers";
printf("%d",-sizeof(str));
}
(a)14 (b)Compile-Time Error (c)-15 (d)-14
Ans. (d)
_________________________________________________________________________________________________

[Q011]. What will be the output of the following program :
void main()
{
printf("%d",!(100==100)+1);
}
(a)100 (b)0 (c)1 (d)2
Ans. (c)
_________________________________________________________________________________________________

[Q012]. What will be the output of the following program :
void main()
{
int x=5,y=6,z=2;
z/=y/z==3?y/z:x*y;
printf("%d",z);
}
(a)Compile-Time Error (b)2 (c)0 (d)1
Ans. (c)
_________________________________________________________________________________________________

[Q013]. What will be the output of the following program :
void main()
{
printf("%d %d %d",5,!5,25-!25);
}
(a)5 10 22 (b)5 5 25 (c)5 0 25 (d)5 1 24
Ans. (c)
_________________________________________________________________________________________________

[Q014]. What will be the output of the following program :
int main()
{
int a=500,b=100,c=30,d=40,e=19;
a+=b-=c*=d/=e%=5;
printf("%d %d %d %d %d",a,b,c,d,e);
}
(a)500 100 30 40 4 (b)Run-Time Error (c)700 200 300 10 4 (d)300 -200 300 10 4
Ans. (d)
_________________________________________________________________________________________________

[Q015]. What will be the output of the following program :
void 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");
}
(a)VALID : Success (b)VALID : Failure (c)INVALID (d)None of these
Ans. (a)
_________________________________________________________________________________________________

[Q016]. What will be the output of the following program :
void main()
{
int a=1,b=2,c=3,d=4;
printf("%d",!a?b?!c:!d:a);
}
(a)1 (b)2 (c)3 (d)4
Ans. (a)
_________________________________________________________________________________________________

[Q017]. What will be the output of the following program :
void main()
{
int i=12345,j=-13579,k=-24680;
long ix=123456789;
short sx=-2222;
unsigned ux=5555;
printf("\n%d %d %d %ld %d %u",i,j,k,ix,sx,ux);
printf("\n\n%3d %3d %3d\n%3ld %3d %3u",i,j,k,ix,sx,ux);
printf("\n\n%8d %8d %8d\n%15ld %8d %8u",i,j,k,ix,sx,ux);
printf("\n\n%-8d %-8d\n%-8d %-15ld\n%-8d %-8u",i,j,k,ix,sx,ux);
printf("\n\n%+8d %+8d\n%+8d %+15ld\n%+8d %8u",i,j,k,ix,sx,ux);
printf("\n\n%08d %08d\n%08d %015ld\n%08d %08u",i,j,k,ix,sx,ux);
}
Ans. 12345 -13579 -24680 123456789 -2222 5555

12345 -13579 -24680
123456789 -2222 5555

12345 -13579 -24680
123456789 -2222 5555

12345 -13579
-24680 123456789
-2222 5555

+12345 -13579
-24680 +123456789
-2222 5555

00012345 -0013579
-0024680 000000123456789
-0002222 00005555
_________________________________________________________________________________________________

[Q018]. What will be the output of the following program :
void main()
{
int i=12345,j=0xabcd9,k=077777;
printf("%d %x %o",i,j,k);
printf("\n%3d %3x %3o",i,j,k);
printf("\n%8d %8x %8o"i,j,k);
printf("\n%-8d %-8x %-8o",i,j,k);
printf("\n%+8d %+8x %+8o",i,j,k);
printf("\n%08d %#8x %#8o",i,j,k);
}
Ans. 12345 abcd9 77777
12345 abcd9 77777
12345 abcd9 77777
12345 abcd9 77777
+12345 abcd9 77777
00012345 0xabcd9 077777
_________________________________________________________________________________________________

[Q019]. What will be the output of the following program :
void main()
{
char c1='A', c2='B', c3='C';
printf("%c %c %c",c1,c2,c3);
printf("\n%c%c%c",c1,c2,c3);
printf("\n%3c %3c %3c",c1,c2,c3);
printf("\n%3c%3c%3c",c1,c2,c3);
printf("\nc1=%c c2=%c c3=%c",c1,c2,c3);
}
Ans. A B C
ABC
A B C
A B C
c1=A c2=B c3=C
_________________________________________________________________________________________________

[Q020]. What will be the output of the following program :
void main()
{
float a=2.5, b=0.0005, c=3000.;
printf("%f %f %f",a,b,c);
printf("\n%3f %3f %3f",a,b,c);
printf("\n%8f %8f %8f",a,b,c);
printf("\n%8.4f %8.4f %8.4f",a,b,c);
printf("\n%8.3f %8.3f %8.3f",a,b,c);
printf("\n%e %e %e",a,b,c);
printf("\n%3e %3e %3e",a,b,c);
printf("\n%12e %12e %12e",a,b,c);
printf("\n%8.2e %8.2e %8.2e",a,b,c);
printf("\n%-8f %-8f %-8f",a,b,c);
printf("\n%+8f %+8f %+8f",a,b,c);
printf("\n%08f %08f %08f",a,b,c);
printf("\n%#8f %#8f %#8f",a,b,c);
printf("\n%g %g %g",a,b,c);
printf("\n%#g %#g %#g"a,b,c);
}

Ans. 2.500000 0.000500 3000.000000
2.500000 0.000500 3000.000000
2.500000 0.000500 3000.000000
2.5000 0.0005 3000.0000
2.500 0.001 3000.000
2.500000e+000 5.000000e-004 3.000000e+003
2.500000e+000 5.000000e-004 3.000000e+003
2.500000e+000 5.000000e-004 3.000000e+003
2.5000e+000 5.0000e-004 3.0000e+003
2.50e+000 5.00e-004 3.00e+003
2.500000 0.000500 3000.000000
+2.500000 +0.000500 +3000.000000
2.500000 0.000500 3000.000000
2.500000 0.000500 3000.000000
2.5 0.0005 3000
2.500000 0.000500 3000.000000
_________________________________________________________________________________________________

[Q021]. What will be the output of the following program :
void main()
{
char str[]="C For Swimmers";
printf("%s",str);
printf("\n%.5s",str);
printf("\n%8.*s",5,str);
printf("\n%-10s %.1s",str+6,str);
}
Ans. C For Swimmers
C For
C For
Swimmers C
_________________________________________________________________________________________________

[Q022]. What will be the output of the following program :
void 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);
}
[NOTE : 3 values entered by the user are:100 200 300]
(a)1 2 3 (b)100 200 300 (c)100 200 3 (d)100 300 3
Ans. (d)
_________________________________________________________________________________________________

[Q023]. What will be the output of the following program :
void main()
{
char line[80]; // Max. length=80 Chars
scanf("%[^,]s",line);
printf("\n%s",line);
}
[NOTE : THE USER INPUT IS:Dear Friends, What is the output?]
(a)Compile-Time Error (b)Dear Friends (c)What is the output? (d)None of these
Ans. (b)
_________________________________________________________________________________________________

[Q024]. What will be the output of the following program :
void main()
{
char a,b,c;
scanf("%c%c%c",&a,&b,&c);
printf("a=%c b=%c c=%c",a,b,c);
}
[NOTE : THE USER INPUT IS :A B C]
(a)a=A b=B c=C (b)a=A b= c=B (c)a=A b= c=C (d)None of these
Ans. (b)
_________________________________________________________________________________________________

[Q025]. What will be the output of the following program :
void main()
{
int i=1;
float f=2.25;
scanf("%d a %f",&i,&f);
printf("%d %.2f",i,f);
}
[NOTE : THE USER INPUT IS:5 5.75]
(a)1 2.25 (b)5 5.75 (c)5 2.25 (d)None of these
Ans. (c)
_________________________________________________________________________________________________

[Q026]. What will be the output of the following program :
void main()
{
char a,b,c;
scanf("%c %c %c",&a,&b,&c);
printf("a=%c b=%c c=%c",a,b,c);
}
[NOTE : THE USER INPUT IS :ABC DEF GHI]
(a)a=ABC b=DEF c=GHI (b)a=A b=B c=C (c)a=A b=D c=G (d)None of these
Ans.
_________________________________________________________________________________________________

[Q027]. What will be the output of the following program :
void main()
{
char a[80],b[80],c[80];
scanf("%1s %5s %3s",a,b,c);
printf("%s %s %s",a,b,c);
}
[NOTE : THE USER INPUT IS:CMeansSea Ocean Vast]
(a)C O V (b)C Means Sea (c)C Ocean Vas (d)None of these
Ans. (b)
_________________________________________________________________________________________________

[Q028]. What will be the output of the following program :
void main()
{
int a,b,c;
scanf("%1d %2d %3d",&a,&b,&c);
printf("Sum=%d",a+b+c);
}
[NOTE : THE USER INPUT IS :123456 44 544]
(a)Sum=480 (b)Sum=594 (c)Sum=589 (d)None of these
Ans. (a)
_________________________________________________________________________________________________

[Q029]. What happens when the following program is executed :
void main()
{
char line[80];
scanf("%[^1234567890\n]",line);
}
(a)Accepts the string that contains DIGITS only.
(b)Accepts the string that contains DIGITS and NEWLINE characters.
(c)Accepts the string that contains anything other than the DIGITS and NEWLINE characters.
(d)None of these
Ans. (c)
_________________________________________________________________________________________________

[Q030]. What happens when the following program is executed :
void main()
{
char line[80];
scanf("%[^*]",line);
}
(a)Accepts the string that contains DIGITS & ALPHABETS only.
(b)Accepts the string that contains * or asterisk characters only.
(c)Accepts the string that contains anything other than the * or asterisk character.
(d)None of these
Ans. (c)
___________________________________________________________________________

Thanx for using "C For Swimmers".
Regarding this material, you can send Bug Reports, Suggestions, Comments,etc. to jayukudari@gmail.com

Take up a Mock Test on C

1) main()

{

extern int i;

i=20;

printf("%d",i);

}

a)20 b)no output c)compilation error d) none of these

2) main()

{

char *p;

printf("%d %d ",sizeof(*p),sizeof(p));

}

a) 1 2 b) 2 1 c) 1 1 d) 2 2

3) what is the output of following code

void e(int);

main()

{

int a;

a=3;

e(a);

}

void e(int n)

{

if(n>0)

{

e(n--);

printf("%d",n);

e(--n);

}

}

a) 0 1 2 1 b) 0 1 2 0 c) 12 0 1 d) 0 2 1 1

4) output for this program is....

main()

{

char *p;

char buff[10]= {1,2,3,4,5,6,9,8};

p= (buff+1)[5];

printf("%d",p);

a)5 b) 9 c) 6 d)none of these

5) main()

{

int i;

printf("%d",scanf("%d",&i)); // value 10 is given as input here

}

a) 1 b) 10 c) &i d) null

6) #include

void main()

{

union a

{

int i;

char ch[2];

};

union a u;

u.ch[0]= 3;

u.ch[1]= 2;

printf("%d %d %d",u.ch[0],u.ch[1],u.i);

}

a) 3 2 515 b)515 2 3 c) 3 2 5 d) none of these

7) int aaa() {printf(“Hi”);}

int bbb(){printf(“hello”);}

int ccc(){printf(“bye”);}

main()

{

int ( * ptr[3]) ();

ptr[0] = aaa;

ptr[1] = bbb;

ptr[2] =ccc;

ptr[2]();

}

a) Hi b) hello c) bye d)Type mismatch in redeclaration



8) void main()

{

int const * p=5;

printf("%d",++(*p));

}

a) 5 b) 6 c) &p d) compiler error



9) main()

{

struct student

{

char name[30];

struct date dob;

}stud;

struct date

{

int day,month,year;

};

scanf("%s%d%d%d", stud.rollno, &student.dob.day, &student.dob.month, &student.dob.year);

}

a) It scans perfectly with error b) scanf format is incorrect c) No Error d) compilation Error

10) main()

{

int i=4,j=7;

j = j || i++ && printf("YOU CAN");

printf("%d %d", i, j);

}



a) 4 1 b) Incorrect compound condition c) 4 7 d) No output



11) main()

{

int a=2,*f1,*f2;

f1=f2=&a;

*f2+=*f2+=a+=2.5;

printf("\n%d %d %d",a,*f1,*f2);

}



a) 16 16 16 b) 16 16 c) 2 16 16 d) 2.5 16 16



12) main()

{

float f=5,g=10;

printf("%f\n",f<<2);

printf("%lf\n",g%f);



}



a) 20 0 b) left shift cannot be applied to float c) mod operation cannot be applied to float d) both b and c



13) main()

{

enum{i=10,j=20,k=50};

printf("%d\n",++k);

}

a) 50 b) 51 c) No Error d) Error: constant value cannot

be incremented.



14) main()

{

int *j;

{

int i=10;

j=&i;

}

printf("%d",*j);

}

a)10 b) syntax error c) garbage value d) No Error & No output



15)#define int char

main()

{

int i=65;

printf("sizeof(i)=%d",sizeof(i));

}

a) sizeof(i)=1 b)sizeof(i)=2 c)sizeof(i)=65 d)Error



16) #include‹stdio.h›

main()

{

char s[]={'a','b','c','\n','c','\0'};

char *p,*str,*str1;

p=&s[3];

str=p;

str1=s;

printf("%d",++*p + ++*str1-32);

}

a) 98 b)11 c) 22 d) 77



17) #include‹stdio.h›

main()

{

int a[2][2][2] = { {10,2,3,4}, {5,6,7,8} };

int *p,*q;

p=&a[2][2][2];

*q=***a;

printf("%d----%d",*p,*q);

}

a) 6 b) 10 c) some garbage value d) No output

18) main()

{

static char names[5][20]={"pascal","ada","cobol","fortran","perl"};

int i;

char *t;

t=names[3];

names[3]=names[4];

names[4]=t;

printf("%s",names[3]);

}

a) perl b) fortran c) compilation Error d) Linker Error

19) which of the below three functions are likely cause the problem with pointer

int *f1(void)

{

int x=10;

return &x;

}

int *f2(void)

{

int *ptr;

*ptr=10;

return ptr;

}

int *f3(void)

{

int *ptr;

ptr= (int*)malloc(sizeof(int));

return ptr;

}

a) only f3 b) only f1 and f2 c) only f1 and f3 d) f1,f2.f3

20) main()

{

char *p;

p="Hello";

printf("%c\n",*&*p);

}

a) H b) address of p c) compilation Error d) None

21) How many bytes are occupied by the near pointer?

a) 16 b) 2 c) 32 d) 1

22) p-- executes faster than p-1 because

a) p uses registers b) p-- is a single instruction c) -- is faster than - d) None

23) The associativity of ! operator is

a) Right to Left b) Left to Right c) (a) for arithmetic d) (a) for relational

(b) for relational (b) for arithmetic

24) main()

{

double me=1.1;

long double you=1.1;

if(me==you)

printf(“I Love U”);

else

printf(“I Hate U”);

}

a) I Love U b) I Hate U c) Compilation Error d) Run-time Error

25) main()

{

show();

}

void show()

{

printf(“I am greatest”);

}

a) I am greatest b) I Am Greatest c) Compiler Error d) Linker Error

26) main()

{

char not;

not =!2;

printf(“%d”,not);

}

a) 0 b) syntax Error c) Linker Error d) Run-time Error

27) main()

{

int k=ret(sizeof(float));

printf(“%d”,++k);

}

int ret(int ret)

{

ret+=2.5;

return ret;

}

a) Typecasting required b) 7 c) 6 d) 6.5

28) #define sqr(int) (int * int)

main()

{

float a;

a=sqr(3.0+2.0);

printf(“%f”,a);

}

a) 25.0 b) 11.0 c) 9.0 d) 4.0

29) main()

{

unsigned int i=10;

while(i-- >=0)

printf(“%u”,i);

}

a) 10 9 8 0 b) 10 8 7 6 5 4 3 2 1 0 c) While loop never ends

d) cannot decrement unsigned value

30) main()

{

char *str=”hello”;

char *ptr=str;

char least=127;

while(*ptr++)

least=(*ptr

printf(“%d”,least);

}

a) 127 b) 1 c) 0 d) Incompatible type conversion

31) main()

{

char *ptr=”%%s”;

printf(++ptr,ptr);

}

a) ptr b) %s c) Incorrect pointer addition d) %%s

32) main()

{

int z,x=5,y=-10,a=4,b=2;

z = x++ - --y * b / a;

printf(“%d”,z);

}

a) 5 b) 6 c) 10 d) 11

33) int *fun()

{

static int k=5;

printf(“%d”,k);

return &k;

}

void main()

{

fun();

*(fun())=7;

fun();

}

a) 5 7 b) 5 6 7 c) 5 5 7 d) 5 5 5

34) struct node *nptr, *sptr; /* pointers to linked list */

for(nptr=sptr; nptr ;nptr=nptr->next)

{

free(nptr);

}

a) It will not work correctly since the for loop covers the entire list.

b) It may fail since each node nptr is freed before its next address can be accessed

c) In the for loop, the assignment nptr=nptr->next must be replaced with nptr=nptr.next

d) No memory location is released.

35) Pick up the possible statements which can multiply the value in i by 4 form the following list

I) i*4 II) i<<2>>4 IV) i<<4

a) I only b) both I and II c) III only d) both III and IV

36) main()

{

int testarray[3][2][2]={1,2,3,4,5,6,7,8,9,10,11,12};

printf(“%d”,testarray[2][1][0]);

}

a) 5 b) 10 c) 11 d) 3

37) printf(“%d”, 11 ^ 5); What will be printed?

a) 6 b) 5 c) 10 d)14

38) main()

{

int i=0x1234;

char *p;

p=&i;

printf(“%c”,*p);

}

a) 4 b) Incompatible data type c) No output d) null

39) main()

{

void *p, *q;

p=(void *)1008;

q=(void *)1000;

printf(“%d”,p-q);

}

a) 4 b) 8 c) Compilation Error d) Linker Error

40) Pick out the equivalent postfix expression for this infix expression :

((A + B) * C – (D – E) ^ (F + G))

a) AB+C*DE - - FG + ^

b) ABC*DE - - FG ^ G +

c) AB+CDE - - * FG+^

d) AB+C*DE - -FG^+

41) A binary tree with 40 nodes has ________ branches?

a) 40 b) 41 c) 39 d) 20

42) How many different trees are possible with 10 nodes?

a) 1020 b) 1000 c) 1014 d) 1019

43) Consider an tree implemented using array holds ABCDEFG-H- - - - IJ, where - denotes no value. Pick out the correct post order traversal result.

a) HDEBFIJGCA

b) DHBEAFCIGJ

c) ABDHECFGIJ

d) ABCDEFGHIJ

44) If the records that it’s sorting are in main memory then the sort is called as

a) Internal b) external c) stable d) None

45) Consider an array holding tree information 11 12 13 8 6 5 17 20. If you heapify it what will be the contents of the array?

a) 12 11 8 6 5 17 20 13

b) 20 12 17 11 6 5 13 8

c) 20 12 11 17 13 6 5 8

d) 17 12 11 20 6 8 5 13

46) To implement a node holding another node in a linked list which of the following you will use?

a) Single structure

b) self-referential structures

c) structures within structures

d) both b and c

47) In dealing with a hash clash, a technique is used that builds a linked list of all items whose keys hash to the same values is called

a) chaining b) rehashing c) hash collision d) open addressing

48) A useful tool for specifying the logical properties of a data type is a

a) Abstract data type

b) ADT

c) both a and b

d) None of these

49) In queue the insert operation could be implemented by the statements as

a) q.items[++q.rear]=x

b) ++q.items[q.rear]=x

c) q.items[q.rear++]=x

d) Any of the above

50) A finite set of elements that is empty or is partitioned into three disjoined subsets is called

a) tree b) binary tree c) list d) queue
C For Swimmers
______________

Topic : Discovering C
_____ _____________

*************************************************************************************************
* NOTE : All the programs are tested under Turbo C/C++ compilers. *
* It is assumed that, *
* *=> Programs run under DOS environment, *
* *=> The underlying machine is an x86 system, *
* *=> Necessary header files are included. *
* *=> Program is compiled using Turbo C/C++ compiler. *
* The program output may depend on the information based on this assumptions. *
* (For example sizeof(int) = 2 bytes may be assumed). *
*************************************************************************************************


[Q001]. The following code is not well-written. What does the program do ?
void
main(
){int a=1,
b=2,c=3,d=4;printf("%d %d",
a,b);printf(
" %d %d",c,d);
}

(a)Run-Time Error (b)Compile-Time Error (c)1 2 3 4 (d)None of these
Ans. (d)
_________________________________________________________________________________________________

[Q002]. What will be the output of the following program :
void main()
{
int a=1,b=2,c=3;
c=(--a,b++)-c;
printf("%d %d %d",a,b,c);
}
(a)0 3 -3 (b)Compile-Time Error (c)0 3 -1 (d)0 3 0
Ans. (c)
_________________________________________________________________________________________________

[Q003]. What will be the output of the following program :
void main()
{
int a=1,b=2,c=3,d=4,e;
e=(a,a)+(b,c)+(c,d)-(d,b);
printf("%d",e);
}
(a)Compile-Time Error (b)10 (c)6 (d)2
Ans. (c)
_________________________________________________________________________________________________

[Q004]. What will be the output of the following program :
void main()
{
float val=2.;
printf("%.2",val);
}
(a)Compile-Time error (b)2.00 (c)%.2 (d)2.000000
Ans. (b)
_________________________________________________________________________________________________

[Q005]. What will be the output of the following program :
void main()
{
int a=5;
int b=6;;
int c=a+b;;;
printf("%d",c);;;;
}
(a)Compile-Time Error (b)Run-Time Error (c)11 (d)None of these
Ans. (c)
_________________________________________________________________________________________________

[Q006]. What will be the output of the following program :
void main()
{
int i,j;
for (i=1; i<=3; i++)
for (j=1; j<3;>
{
if (i == j)
continue;
if ((j % 3) > 1)
break;
printf("%d",i);
}
}
Ans.
_________________________________________________________________________________________________

[Q007]. What will be the output of the following program :
#define swap(a,b) temp=a; a=b; b=temp;
void main()
{
static int a=5,b=6,temp;
if (a > b)
swap(a,b);
printf("a=%d b=%d",a,b);
}
(a)a=5 b=6 (b)a=6 b=5 (c)a=6 b=0 (d)None of these
Ans. (c)
_________________________________________________________________________________________________

[Q008]. What will be the output of the following program :
void main()
{
unsigned int val=5;
printf("%u %u",val,val-11);
}
(a)Compile-Time error (b)5 -6 (c)5 65530 (d)None of these
Ans. (c)
_________________________________________________________________________________________________

[Q009]. What will be the output of the following program :
void main()
{
int x=4,y=3,z=2;
*&z*=*&x**&y;
printf("%d",z);
}
(a)Compile-Time error (b)Run-Time Error (c)24 (d)Unpredictable
Ans. (c)
_________________________________________________________________________________________________

[Q010]. What will be the output of the following program :
void main()
{
int i=5,j=5;
i=i++*i++*i++*i++;
printf("i=%d ",i);
j=++j*++j*++j*++j;
printf("j=%d",j);
}
(a)Compile-Time Error (b)i=1680 j=1680 (c)i=629 j=6561 (d)i=1681 j=3024
Ans. (c) Compiler dependent
_________________________________________________________________________________________________

[Q011]. What will be the output of the following program :
void main()
{
int i=5;
printf("%d %d %d %d %d",++i,i++,i++,i++,++i);
}
(a)Compile-Time Error (b)10 9 8 7 6 (c)9 8 7 6 6 (d)10 8 7 6 6
Ans. (d)
_________________________________________________________________________________________________

[Q012]. What will be the output of the following program :
void main()
{
unsigned ch='Y';
printf("%d",sizeof ch);
}
(a)Compile-Time Error (b)2 (c)4 (d)1
Ans. (b)
_________________________________________________________________________________________________

[Q013]. What will be the output of the following program :
void main()
{
int a=5;
printf("%d");
}
(a)Compile-Time Error (b)5 (c)Unpredictable (d)No Output
Ans. (b)
_________________________________________________________________________________________________

[Q014]. What will be the output of the following program :
void main()
{
int a=5,b=6;
printf("%d");
}
(a)Compile-Time Error (b)5 (c)6 (d)Unpredictable
Ans. (c)
_________________________________________________________________________________________________

[Q015]. What will be the output of the following program :
void main()
{
int a=5,b=6,c=7;
printf("%d %d %d");
}
(a)Compile-Time Error (b)5 6 7 (c)7 6 5 (d)Unpredictable
Ans. (c)
_________________________________________________________________________________________________

[Q016]. What will be the output of the following program :
#define Swap if (a != b) { \
temp=a; \
a = b; \
b = temp; \ //Swapping Done
}
void main()
{
int a=10,b=5,temp;
Swap;
printf("a=%d a=%d",a,b);
}
(a)Compile-Time Error (b)a=5 b=10 (c)a=10 b=5 (d)None of these
Ans. (a)
_________________________________________________________________________________________________

[Q017]. What will be the output of the following program :
void main()
{
int val=50;
void *ptr;
ptr=&val;
printf("%d %d",val,*(int *)ptr);
}
(a)Compile-Time Error (b)50 50 (c)50 0 (d)None of these
Ans. (b)
_________________________________________________________________________________________________

[Q018]. What will be the output of the following program :
void main()
{
int a=5,b=6;
Printf("%d %d %d",a,b,--a*++b);
}
(a)Compile-Time Error (b)5 6 30 (c)4 7 28 (d)None of these
Ans. (a)
_________________________________________________________________________________________________

[Q019]. What will be the output of the following program :
void main()
{
int val=5;
void *ptr;
*(int *)ptr=5;
val=ptr;
printf("%d %d",*(int *)val,*(int *)ptr);
}
(a)Compile-Time Error (b)Unpredictable (c)5 5 (d)None of these
Ans. (c)
_________________________________________________________________________________________________

[Q020]. What will be the output of the following program :
void main()
{
int val=2;
val = - --val- val--- --val;
printf("%d",val);
}
(a)Compile-Time Error (b)3 (c)-1 (d)0
Ans. (c)
_________________________________________________________________________________________________

[Q021]. What will be the output of the following program :
void main()
{
int i,n=10;
for (i=1; i
printf("%d\n",n-i);
}
(a)84 (b)840 (c)852 (d)864
Ans. (c)
_________________________________________________________________________________________________

Thanx for using "C For Swimmers".

Regarding this material, you can send Bug Reports, Suggestions, Comments,etc. jayukudari@gmail.com

U WANNA PLAY WITH C-Programming

C For Swimmers


If u don't know how to swim, learn it now. Otherwise participate in

the competition.


Topic : Playing with 'printf()' statement


***************************************************************************
* NOTE : All the programs are tested under Turbo C/C++ compilers.

*
* It is assumed that,

*
* *=> Programs run under DOS environment,

*
* *=> The underlying machine is an x86 system,

*
* *=> Necessary header files are included.

*
* *=> Program is compiled using Turbo C/C++ compiler.

*
* The program output may depend on the information based on this

assumptions.


* (For example sizeof(int) = 2 bytes may be assumed).


***************************************************************************


[Q001]. What will be the output of the following program :
void main()
{
printf();
}
(a)Run-Time Error (b)Compile-Time Error (c)No Output

(d)None of these
Ans. (b) Since there must be enough arguments for the format.
___________________________________________________________________________

[Q002]. What will be the output of the following program :
void main()
{
printf(NULL);
}
(a)Run-Time Error (b)Compile-Time Error (c)No Output

(d)None of these
Ans. (c) Since NULL is a constant value or NULL pointer value or a NULL

string.
___________________________________________________________________________

[Q003]. What will be the output of the following program :
void main()
{
printf("%%",7);
}
(a)7 (b)Compile-Time Error (c)%

(d)%%
Ans. (c) Since % is a format specifier & excess arguments (more than

required by the format) are
merely ignored.
___________________________________________________________________________

[Q004]. What will be the output of the following program :
void main()
{
printf("//",5);
}
(a)5 (b)Compile-Time Error (c)/

(d)//
Ans. (d) Since / is an escape sequence character & excess arguments (more

than required by the format) are merely ignored.
___________________________________________________________________________

______________________

[Q005]. What will be the output of the following program :
void main()
{
printf("d%",8);
}
(a)8 (b)Compile-Time Error (c)d%

(d)None of these
Ans. (c) Since excess arguments (more than required by the format) are

merely ignored.
___________________________________________________________________________

[Q006]. What will be the output of the following program :
void main()
{
printf("%d"+0,123);
}
(a)123 (b)Compile-Time Error (c)No Output

(d)None of these
Ans. (a) "%d"+0 has no effect on the output operation.
___________________________________________________________________________

[Q007]. What will be the output of the following program :
void main()
{
printf("%d"+1,123);
}
(a)123 (b)Compile-Time Error (c)d

(d)No Output
Ans. (c) "%d"+1 (or > 0) affects the program output by considering "%d" as

string and ignores 123
Where 1 refers to the index i.e. 2nd character in the array or string "%d".
___________________________________________________________________________

[Q008]. What will be the output of the following program :
void main()
{
printf("%d",printf("Hi!")+printf("Bye"));
}
(a)ByeHi!6 (b)Hi!Bye6 (c)Compile-Time Error

(d)None of these
Ans. (b) Since L->R priority & the length of the strings 'Hi!' & 'Bye' is

3+3=6
___________________________________________________________________________

______________________

[Q009]. What will be the output of the following program :
void main()
{
printf("%d",printf("Hi!")*printf("Bye"));
}
(a)ByeHi!6 (b)Hi!Bye9 (c)Hi!Bye
Ans. (b) Since L->R priority & the length of the strings 'Hi!' & 'Bye' is

3*3=9
___________________________________________________________________________

[Q010]. What will be the output of the following program :
void main()
{
printf("%d",printf("")+printf(""));
}
(a)0 (b)No Output (c)Compile-Time Error

(d)None of these
Ans. (a) Since L->R priority & the length of the 2 empty strings are :

0+0=0
___________________________________________________________________________

[Q011]. What will be the output of the following program :
void main()
{
printf("Hi Friends"+3);
}
(a)Hi Friends (b)Friends (c)Hi Friends3

(d)None of these
Ans. (b) Since (base adress)+0 points to the value 'H'. Now the NEW (base

address) equals
(base address)+3 that points to the character 'F'. Thus it prints the

string from 'F' onwards.
___________________________________________________________________________

[Q012]. What will be the output of the following program :
void main()
{
printf("C For ") + printf("Swimmers");
}
(a)Compile-Time Error (b)C For Swimmers (c)Run-Time Error

(d)None of these
Ans. (b) It is a VALID C statement. Change the operators but the output

remains same(NO EFFECT).
___________________________________________________________________________

[Q013]. What will be the output of the following program :
void main()
{
printf("\/\*\-*\/");
}
(a)Run-Time Error (b)\/*-*\/ (c)/*-*/

(d)None of these
Ans. (c) Since \ is an escape sequence character. Be careful while

analyzing such statements.
___________________________________________________________________________

[Q014]. What will be the output of the following program :
int main()
{
int main=7;
{
printf("%d",main);
return main;
}
printf("Bye");
}
(a)Compile-Time Error (b)Run-Time Error (c)7Bye

(d)7
Ans. (d) It is a VALID C statement. Prints 7 and returns the same to the

OS. NOTE: Last printf
statement will not be executed.
___________________________________________________________________________

[Q015]. What will be the output of the following program :
void main()
{
main();
}
(a)Compile-Time Error (b)Run-Time Error (c)Infinite Loop

(d)None of these
Ans. (c) It is a VALID C statement. It is like a recursive function & the

statements get executed
infinite number of times.
___________________________________________________________________________

[Q016]. What will be the output of the following program :
void main()
{
printf("Work" "Hard");
}
(a)Work (b)Hard (c)No Output

(d)WorkHard
Ans. (d) Since L->R priority. First it prints the word 'Work' & then

'Hard'.
___________________________________________________________________________

[Q017]. What will be the output of the following program :
void main()
{
char str[]="%d";
int val=25;
printf(str,val);
}
(a)Compile-Time Error (b)Run-Time Error (c)25

(d)None of these
Ans. (c) It is a VALID C statement. First parameter contains the format

specifier & the Second
parameter contains the actual value 25.
___________________________________________________________________________

[Q018]. What will be the output of the following program :
void main()
{
int val=75;
printf("%d",val,.,.);
}
(a)Compile-Time Error (b)Unpredictable (c)75

(d)None of these
Ans. (b) Output is Unpredictable B'coz there are not enough arguments for

the format. But it is a
VALID C statement.
___________________________________________________________________________

[Q019]. What will be the output of the following program :
void main()
{
int val=10;
printf("%d",val+1,"%d",val--);
}
(a)10 (b)11 10 (c)11 9

(d)10 9
Ans. (a) Since R->L priority. The second format specifier '%d' is an excess

argument and it is
ignored.
___________________________________________________________________________

[Q020]. What will be the output of the following program :
void main()
{
int val=5;
printf("%d %d %d %d",val,--val,++val,val--);
}
(a)3 4 6 5 (b)5 5 6 5 (c)4 4 5 5

(d)None of these
Ans. (c) Since R->L priority.
___________________________________________________________________________

[Q021]. What will be the output of the following program :
void main()
{
int val=5,num;
printf("%d",scanf("%d %d",&val,&num));
}
[NOTE : ASSUME 2 values are entered by the user are stored in the variables

'val' & 'num' respectively.]
(a)1 (b)2 (c)5

(d)None of these
Ans. (b) Since scanf statement returns the number of input fields

successfully scanned, converted
& stored.
___________________________________________________________________________

[Q022]. What will be the output of the following program :
#define Compute(x,y,z) (x+y-z)
void main()
{
int x=2,y=3,z=4;
printf("%d",Compute(y,z,(-x+y)) * Compute(z,x,(-y+z)));
}
(a)40 (b)30 (c)Compile-Time Error

(d)None of these
Ans. (b) Since it is macro function. NOTE : Be careful while doing such

type of calculations.
___________________________________________________________________________

[Q023]. What will be the output of the following program :
void main()
{
int m=10,n=20;
printf("%d %d %d",m/* m-value */,/* n-value */n,m*/* Compute m*n

*/n);
}
(a)Run-Time Error (b)10 20 200 (c)Compile-Time Error

(d)None of these
Ans. (b) Since comments /*...*/ are ignored by the compiler.
___________________________________________________________________________

[Q024]. What will be the output of the following program :
void main()
{
int m=10,n=20;
/* printf("%d",m*n);
}
(a)VALID but No Output (b)VALID : Prints 200 (c)Compile-Time Error

(d)None of these
Ans. (c) Since COMMENT statement not ended properly i.e */ is missing in

the above program.
___________________________________________________________________________

[Q025]. What will be the output of the following program :
void main()
{
int val=97;
"Printing..."+printf("%c",val);
}
(a)Printing...97 (b)97 (c)Compile-Time Error

(d)a
Ans. (d) Since alphabet 'a' is the ASCII equivalent of 97.
___________________________________________________________________________

[Q026]. What will be the output of the following program :
void main()
{
int val=5;
val=printf("C") + printf("Skills");
printf("%d",val);
}
(a)Skills5 (b)C1 (c)Compile-Time Error

(d)CSkills7
Ans. (d) VALID Since 'printf' function return the no. of bytes output.
___________________________________________________________________________

[Q027]. What will be the output of the following program :
void main()
{
char str[]="Test";
if ((printf("%s",str)) == 4)
printf("Success");
else
printf("Failure");
}
(a)TestFailure (b)TestSuccess (c)Compile-Time Error

(d)Test
Ans. (b) VALID Since 'printf' function return the no. of bytes output.
___________________________________________________________________________

[Q028]. What will be the output of the following program :
void main()
{
int val=5;
printf("%*d",val);
}
(a) 5 (b)5 (c)Compile-Time Error

(d)None of these
Ans. (a) VALID Since '*' specifies the precision (i.e. the next argument in

the precision). If no
precision is specified then the value itself will be the precision value.

Thus it prints 5 BLANK
SPACES & then the value 5.
___________________________________________________________________________

[Q029]. What will be the output of the following program :
void main()
{
int val=5;
printf("%d5",val);
}
(a)Compile-Time Error (b)5 (c)55

(d) 5
Ans. (c)
___________________________________________________________________________

[Q030]. What will be the output of the following program :
void main()
}
int val=5;
printf("%d",5+val++);
{
(a)Compile-Time Error (b)5 (c)10

(d)11
Ans. (a) Since incorrect usage of pair of braces } and {. Correct usage :

Each compound statement
should be enclosed within a pair of braces, i.e { and }.
___________________________________________________________________________

Thanx for using "C For Swimmers".
Regarding this material, you can send Bug Reports, Suggestions,

Comments,etc. to jayukudari@gmail.com