Skip to main content

General C++ Programming and Computer Science Sample Paper (Solved)

C++ Basics:
1. What is the correct value to return to the operating system upon the successful completion of a program?A. -1 B. 1 C. 0 D. Programs do not return a value.2. What is the only function all C++ programs must contain?A. start()B. system() C. main() D. program()3. What punctuation is used to signal the beginning and end of code blocks?A. { } B. -> and <- C. BEGIN and END D. ( and ) 4. What punctuation ends most lines of C++ code?A. . B. ; C. : D. ' 5. Which of the following is a correct comment?A. */ Comments */B. ** Comment **C. /* Comment */D. { Comment }6. Which of the following is not a correct variable type?A. floatB. realC. intD. double7. Which of the following is the correct operator to compare two variables?A. :=B. =C. equalD. ==

If Statement:
1. Which of the following is true?A. 1B. 66C. .1D. -1E. All of the above2. Which of the following is the boolean operator for logical-and?A. &B. &&C. D. &3. Evaluate !(1 && !(0 1)).A. TrueB. FalseC. Unevaluatable4. Which of the following shows the correct syntax for an if statement?A. if expressionB. if{ expressionC. if( expression)D. expression if

Loops:
1. What is the final value of x when the code int x; for(x=0; x<10; x++) {} is run?A. 10B. 9C. 0D. 1Note: This quiz question probably generates more email to the webmaster than any other single item on the site. Yes, the answer really is 10. If you don't understand why, think about it this way: what condition has to be true for the loop to stop running?2. When does the code block following while(x<100) execute?A. When x is less than one hundredB. When x is greater than one hundredC. When x is equal to one hundredD. While it wishes3. Which is not a loop structure?A. ForB. Do whileC. WhileD. Repeat Until4. How many times is a do while loop guaranteed to loop?A. 0B. InfinitelyC. 1D. Variable

Functions:
1. Which is not a proper prototype?A. int funct(char x, char y);B. double funct(char x)C. void funct();D. char x();2. What is the return type of the function with prototype: "int func(char x, float v, double t);"A. charB. intC. floatD. double3. Which of the following is a valid function call (assuming the function exists)?A. funct;B. funct x, y;C. funct();D. int funct();4. Which of the following is a complete function?A. int funct();B. int funct(int x) {return x=x+1;}C. void funct(int) {cout&tl;<"Hello"}D. void funct(x) {cout<<"Hello"}
Switch Case:1. Which follows the case statement?A. :B. ;C. -D. A newline2. What is required to avoid falling through from one case to the next?A. end;B. break;C. Stop;D. A semicolon.3. What keyword covers unhandled possibilities?A. allB. contingencyC. defaultD. other4. What is the result of the following code? x=0;
switch(x)
{
case 1: cout<<"One";
case 0: cout<<"Zero";
case 2: cout<<"Hello World";
}A. OneB. ZeroC. Hello WorldD. ZeroHello World

Pointers:
1. Which of the following is the proper declaration of a pointer?A. int x;B. int &x;C. ptr x;D. int *x;2. Which of the following gives the memory address of integer variable a?A. *a;B. a;C. &a;D. address(a);3. Which of the following gives the memory address of a pointer a?A. a;B. *a;C. &a;D. address(a);4. Which of the following gives the value stored in pointer a?A. a;B. val(a);C. *a;D. &a;5. Which of the following is the proper keyword to allocate memory?A. newB. mallocC. createD. value6. Which of the following is the proper keyword to deallocate memory?A. freeB. deleteC. clearD. remove

Structures:
1. Which of the following accesses a variable in structure b?A. b->var;B. b.var;C. b-var;D. b>var;2. Which of the following accesses a variable in structure *b?A. b->var;B. b.var;C. b-var;D. b>var;3. Which of the following is a properly defined struct?A. struct {int a;}B. struct a_struct {int a;}C. struct a_struct int a;D. struct a_struct {int a;};4. Which properly declares a variable of struct foo?A. struct foo;B. foo var;C. foo;D. int foo;

Arrays:
1. Which of the following correctly declares an array?A. int anarray[10];B. int anarray;C. anarray{10};D. array anarray[10];2. What is the index number of the last element of an array with 29 elements?A. 29B. 28C. 0D. Programmer-defined3. Which of the following is a two-dimensional array?A. array anarray[20][20];B. int anarray[20][20];C. int array[20, 20];D. char array[20];4. Which of the following correctly accesses the seventh element stored in foo, an array with 100 elements?A. foo[6];B. foo[7];C. foo(7);D. foo;5. Which of the following gives the memory address of the first element in array foo, an array with 100 elements?A. foo[0];B. foo;C. &foo;D. foo[1];

Strings:
1. Which of the following is a static string?A. Static StringB. "Static String"C. 'Static String'D. char string[100];2. What character ends all strings?A. '.'B. ' 'C. '\0'D. '\n'3. Which of the following reads in a string named x with one hundred characters?A. cin.getline(x, 100, '\n');B. cin.getline(100, x, '\n');C. readline(x, 100, '\n');D. read(x);4. Which of the following functions compares two strings?A. compare();B. stringcompare();C. cmp();D. strcmp();5. Which of the following adds one string to the end of another?A. append();B. stringadd();C. strcat();D. stradd();

File I/O :1. Which of the following classes handlers file input?A. ofstreamB. ifstreamC. instreamD. inputfile2. Which of the following is not a valid ofstream argument?A. ios::appB. ios::truncC. ios::noreplaceD. ios::create
3. What does ios::ate mean as an argument to ofstream?A. Open file, but do not create.B. Open file, create.C. Open file for read access only.D. Open file, set the position to the end.4. How would you output to an open file named a_file?A. a_file.out("Output");B. a_file="Output";C. a_file<<"Output";D. a_file.printf("Output");
5. What header file contains C++ file I/O instructions?A. iostream.hB. fstream.hC. infstream.hD. outstream.h

Typecasting:
1. Which header file do you need to include to use typecasting? A. iostream.hB. ctype.hC. math.hD. None
2. Which is a valid typecast?A. a(char);B. char:a;C. (char)a;D. to(char, a);
3. Why can typecasting be dangerous?A. Some conversions are not defined, such as char to int.B. You might permanently change the value of the variable.C. You might temporarily lose part of the data - such as truncating a float when typecasting to an int.D. There are no dangers.
4. Which is a good use for typecasting?A. To allow division of two integers to return a decimal value.B. To allow your program to use nothing but integers.C. To change the return type of a function.D. To swap variables rapidly.
5. Which conversion is not possible?A. int to floatB. float to intC. char to floatD. All are possible

C++ Classes:
1. What purpose do classes serve?A. data encapsulationB. providing a convenient way of modeling real-world objectsC. simplifying code reuseD. all of the above
2. Which is not a protection level provided by classes in C++?A. protectedB. hiddenC. privateD. public
3. What value must a destructor return?A. A pointer to the class.B. An object of the class.C. A status code determining whether the class was destructed correctlyD. Destructors do not return a value.4. Which of the following is a valid class declaration? A. class A { int x; };B. class B { } C. public class A { }D. object A { int x; };
5. Which functions will every class contain?A. NoneB. ConstructorC. DestructorD. Both a constructor and a destructor

Inline Function in C+ +:
1. What does the inline keyword do?A. Indicates a function declarationB. Tells the compiler to use the function only within the same source code fileC. Causes all function calls to be replaced by the code from the functionD. Allows one-line function declarations
2. Why would you want to use inline functions?A. To decrease the size of the resulting programB. To increase the speed of the resulting programC. To simplify the source code fileD. To remove unnecessary functions
3. Which of the following is a limit on inline functions?A. Inline functions cannot return a value. B. Inline functions must resturn a value.C. Inline functions must be less than ten lines.D. The compiler may choose to ignore an inline directive.
4. Which of the following is a valid inline for function foo? A. inline void foo() {}B. void foo() inline {} C. inline:void foo() {} D. None of the above5. How can you ensure that an inline function isn't inlined for a particular function call for function foo?A. unline x(); B. noexpand x(); C. x(); D. This is not possible on a case-by-case basis

Accepting Command-Line Arguments:
1. What variables stores the number of arguments to a program?A. argcB. argvC countD. arglen
2. What is argv[0]?A. The number of arguments to the programB. The name of the programC. The first argument to the programD. This syntax is illegal
3. What type is argv?A. char * B. intC. char ** D. It's not a variable
4. In what order do the two command line variables appear in the definition of main? A. Count then argument arrayB. Argument array then countC. They don't appear in the definition of main D. There is only one argument.
5. What does the argument count variable store? A. the number of arguments B. the number of arguments plus oneC. the number of arguments minus one D. The total size of the argument array

Comments

Popular posts from this blog

The Missing Mail | Class IX - Interact in English

NCERT / CBSE Literature Reader for English Course (Communicative) Important Exercise Questions Q.3: (a) Why is Ramanujam worried about getting his daughter married? Give four reasons. (b) How does the postman console and guide Ramanujam and his family during each of the instances you have listed in 3 (a)? Ans 3(a): Ramanujam is worried as he could not find a suitable match to marry his daughter off which was getting delayed because of different reasons. The four causes of his worriedness are - (i) Sometimes horoscopes did not match, (ii) Sometimes the girl’s appearance were not approved, (iii) At times there were problems of too much dowry and other financial matters, (iv) The season was closing with only three more auspicious dates left, whereas, he was not able to finalise any alliance by that time. Ans 3(b): First instance - When Ramanujam said that horoscopes did not agree Thanappa consoled and guided him by saying that he should not utter inauspicious words and when the God wills

Carbon and it's Compounds

Introduction Carbon is an element which is of immense significance to us in both its elemental form and in the combined form. Bonding in Carbon - The Covalent Bond Although there are more than hundred elements around us we do not find these elements in their native form in nature. This is because most of these elements are highly reactive. Properties of Covalent Compounds A covalent bond can be formed in different ways. When a bond is formed by mutual sharing of one pair of electrons it is known as a 'single covalent bond', or simply 'a single bond'. Types of Covalent Bonds Types of covalent bonds are Single Bond, Double Bond , Triple Bond. Tetravalency in Carbon A carbon atom has a total of six electrons occupying the first two shells, i.e., the K-shell has two electrons and the L-shell has four electrons. Allotropes of Carbon The existence of one element in different forms, having different physical properties, but similar chemical properties is known as allotropy. Am

ENGLISH (Communicative) Sample Question Paper 5

Sample Paper – 2009 Class – XSubject – ENGLISH (Communicative) General instructions: The paper consist of FOUR sections: SECTION A (READING) - 20 Marks SECTION B (WRITING) - 30 Marks SECTION C (GRAMMAR) - 20 Marks SECTION D (LITERATURE) - 30 Marks Attempt all the questions. Do not write anything on the question paper. All the answers must be correctly numbered as in the question paper. And written in the answer sheets provided to you. Attempt all questions in each section before going on to the next section. Read each question carefully and follow the instructions. Strictly adhere to the word limit given with each question. Marks will be deducted for exceeding the word limit. SECTION A (READING) – 20 MARKS A1. Read the following passage and answer the following questions: [12] THE TUITION TRAP 1. Given the general awareness of the woeful condition of our State sch