Friday, 7 June 2013

Loop Question 1

What will be output of following c code?

#include<stdio.h>
extern int x;
int main(){
    do{
        do{
             printf("%o",x);
         }
         while(!-2);
    }
    while(0);
    return 0;
}
int x=8;



EXPLANATION


Output: 10
Explanation:
Here variable x is extern type. So it will search the definition of variable x. which is present at the end of the code. So value of variable x =8
There are two do-while loops in the above code.  AS we know do-while executes at least one time even that condition is false.  So program control will reach  at printf statement at it will print octal number 10 which is equal to decimal number 8.
Note: %o is used to print the number in octal format.
In inner do- while loop while condition is ! -2 = 0
In C zero means false.  Hence program control will come out of the inner do-while loop.   In outer do-while loop while condition is 0. That is again false. So program control will also come out of the outer do-while loop.

Tuesday, 21 May 2013

QUIZ 26-30 ANSWERS

26. 
_____ variables remain in memory until the program ends
Area
Global
Local
Reference
Value
Answer: Option B

27.
The outline or the definition of a function is called its
beta test
Forerunner
Outline
Prototype
Answer: Option D

28. 
Which of the following is false?
Data stored in an array can be accessed faster than data stored in a disk file
Data stored in an array needs to be entered only once, typically at the beginning of the program
Arrays allow the programmer to store information in the computer's internal memory
When using arrays, you will have fewer variable names to remember
None of the preceding statements are false
Answer: Option E

29. 
A function typically contains
the function header
the function braces
the return statement, if it's value- returning function
a display message
All of the above
Answer: Option E


30. 
A variable's _____ indicates which portions of the program can use the variable
Area
extent
Lifetime
reach
scope
Answer: Option E

Monday, 20 May 2013

QUIZ 21-25

21. 
A group of related fields that contain all of the data about a specific person, place, or thing is called a
data file
field file
program file
Record
Answer: Option D

22. 
To send output to a file, you need to include the _____ header file in your program
file.h
fstream.h
iomanip.h
iostream.h
of stream.h
Answer: Option B

23. 
A C++ _____ is a program that runs in a DOS window
Algorithm
cast application
console application
source application
Answer: Option C

24. 
A difference, between reference variables and pointers is that
reference variables are easier to use
pointers are easier to use
reference variables are more flexible
no difference exists between reference variables and pointers
Answer: Option A



25. 
A 'C function does not contain
a function header
argument declarations
other 'C' functions
function body
None of the above
Answer: Option C

Thursday, 16 May 2013

Find output

#include <stdio.h>
int main()
{
int mar[5]={0,1,2,3,4};
int j,m,i;
i=++mar[0];
j=mar[1]++;
m=mar[i++];
printf("%d %d %d\n\n", i,j,m);
return 0;
}


Answer: i=2, because you increment it in m=mar[i++], j = 1, because the increment carried out after the assignment and m=2, because m=mar[2] => 2 1 2

Friday, 10 May 2013

QUIZ ANSWERS 16-20

QUIZ ANSWERS 16-20

16. 
The generic type in a template function
must be T
can be T
cannot be T for functions you create, but may be for C++'s built-in functions
cannot be T
Answer: Option B


17. 
A function that is called automatically each time an object is destroyed is a
Constructor
destructor
Destroyer
terminator
Answer: Option B

18. 
A function can
return a value
perform a task
change value of actual arguments in call by reference
a, b, c above are all true
None of the above
Answer: Option D


19. 
The statement float values[]={3.14, -7.86, 36.96, 4.87};
assigns 36.96 to values[2]
assigns -7.86 to values[2]
gives an error message
assign 14 to values[2]
Answer: Option A


20. 
When the compiler places a copy of a small function's statements directly into a program, the function is said to be _____
Overloaded
mangled
inline
redundant
Answer: Option C