Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

C++ Data Types and Type Conversions - Prof. Simon, Summaries of C programming

The need for data types in c++, the different data types available in c++ along with their representations and sizes, and the various types of type conversions in c++. It also covers topics such as string handling functions, constructors, static data and member functions, function overloading, abstract classes, pure virtual functions, friend functions, exception handling, function templates, class templates, and file i/o operations. A comprehensive overview of these fundamental concepts in c++ programming, making it a valuable resource for students and developers looking to deepen their understanding of the language.

Typology: Summaries

Pre 2010

Uploaded on 08/14/2024

Nada.Shhedeh
Nada.Shhedeh 🇸🇾

1 document

1 / 27

Toggle sidebar

Related documents


Partial preview of the text

Download C++ Data Types and Type Conversions - Prof. Simon and more Summaries C programming in PDF only on Docsity! Question Bank Programme: B.Tech. (IT) Subject Name: Object Oriented Programming using C++ L: 3 T: 0 P: 0 Semester: 3 Subject Code: PCIT-102 Batch 2018 and onwards Class D2IT A and B Part-A Fundamental Concepts of a Programming Language 2 Marks: 1. Draw a diagram to represent the basic structure of a programin C++. 2. What do you mean by a token? 3. Differentiate between keywod and identifier. 4. Compare and contrast the variables and constants in C++. What are the rules to be followed for identifiers? 5 Marks 5. What is the need of data types in C++? Describe different data types alongwith their reprsentations and size in C++. 6. Give classification of operators available in C++ with the help of neat and clean diagram. 7. Define ternary operator. Compare it with if and if-else statement. 8. What do you mean by oprator precedence? 9. What is the needof type conversion? Discuss different types of type conversion in C++. 10 Marks 10. Classify the different statements available in C++. 11. Differentiate between nested if-else and switch statement. 12. Compare and contrast for, whileand do-while looping statements. 13. Differentiate between break and continue statement. 14. Why the use of goto statement is not good for quality programming? 15. What is the need of array. Discuss different types of arrays. 16. Discuss different string handling functions available in C++. Object Oriented Paradigm 2 Marks: 1. What is the need of Object Oriented Programming paradigm? 2. Define Encapsulation and Data hiding. 3. Define Data Abstraction. 4. Define Data members. 5. Define Member functions. 6. Define Inheritance. 7. Define Polymorphism. 5 Marks: 8. Compare and contrast the structured programming and object oriented programming. 9. What are the features of Object oriented programming. 10. List and define the two types of Polymorphism. 11. Define Dynamic Binding. 12. Define Message Passing. 13. List some benefits of OOPS. 14. List out the applications of OOP. 15. What is the return type of main ()? 10 Marks: 16. Explain the concept of polymorphism by an example in C++. 17. Compare and Contrast late binding and early binding. Classes and Objects 2 Marks: 1. Define class and objects. 2. Write down the syntax and example to create a class. 3. Define reference variable. Give its syntax. 4. Define instance variables. 5 Marks: 5. What are the different ways to define member functions of a class. What is the role of scope resolution operator in the definition of member function? 6. What is the need of passing objects as arguments. Discuss different ways to pass objects as arguments to a function. 7. Discuss the benefits of retrurning objects from functions. 10 Marks: 8. Write a program to add two complex numbers using object as arguments. 9. Write a program to add two distances. Object Initialization and Cleanup 2 Marks: 1. Discuss the use of public, private and protected access specifiers and their visibility in the class. 2. What is constructor? 5 Marks 2. Disfferentate between pass by value and pass by reference. Also explain the pass by address in C++. 3.What is the need of constructor? How it is different from the member function? 4. Discuss default constructor and parameterized constructor with the help of an example in C++. 5. Write down the example of dynamic constructor in C++. 6. What is copy constructor? 7. Explain the use of destructor in C++. 10 Marks: 8. What is the significance of static data and member functions in C++? 9. Write down the program to demonstrate static keyword in c++. Overloading and Inheritance 2 Marks: 1. What is the need of overloading operators and functions? 2.Write down the example to overload unary and binary operators in C++. 5 Marks: 3. Write down a C++ program to implement function overloading. MCQ Questions (2 Marks Each) 1. What is the output of the following code? #include<iostream.h> #include<string.h> void main() { cout<<strlen(“Hello, World.\n”)<<”\n”; } (a) 14 (b) 13 (c) 12 (d) None 2. What is the output of the following code? #include<iostream.h> void main() { /* this is /* an example */ of nested comment */ cout<<123<<endl; } (a) 123 (b) Compile time error (c) None (d) Run time Error 3. What is the output of the following code? #include<iostream.h> void main() { cout << ; } (a) 1 (b) Compile time error (c) NIL (d) None 4. What is the output of the following code? #include<iostream.h> void main() { int a = 20; int &n = a; n=a++; a=n++; cout<<a <<”,”<<n<<endl; } (a) 20, 20 (b) 20, 21 (c) 21, 22 (d) None 5. What is the output of the following code? #include<iostream.h> void main() { int a = 20,b=100; int &n = a; n=a++; n = &b; cout<<a <<”,”<<n<<endl; } (a) 21, 21 (b) 20, 21 (c) 21, 22 (d) Error 6. What is the output of the following code? #include<iostream.h> void main() { bool a=10; cout<<a<<endl; } (a) 10 (b) false (c) 1 (d) Error 7. What is the output of the following code? #include<iostream.h> void main() { int main; main = 100; cout<<main++<<endl; } (a) 101 (b) 100 (c) None (d) Error: one cannot use main as identifier 19. Sending a copy of data to a program module is called . (a) recursion (b) passing a reference (c) passing a value (d) None 20. Each generic type in a template function definition is preceded by the keyword (a) class (b) type (c) function (d) template 21. Which of the followings is not a C++ opoerator? (a) ^= (b) .* (c) &= (d) ->> 22. What is the output of the following code? #include<iostream.h> void main() { char p[]="This is a test"; cout<<sizeof(p)<<","<<strlen(p); } (a) 14, 14 (b) 15, 14 (c) 14, 15 (d) 15,15 23. What is wrong with the following program? #include<iostream.h> void main() { int a[5] = {0}; for(int i=0;i<2;i++) a[i]=i; for(int i=0;i<5;i++) cout<<a[i]<<endl; } (a) Array ‘a’ is not initialized properly (b) There is no problem (c) Redeclaration of variable ‘i’ (d) There is a run time error 24. What is the output of the following code? #include<iostream.h> void main() { int a[5] = {100,2,3,22,400}; int b[5]; b=a; for(int i=0;i<5;i++) cout<<b[i]<<endl; } (a) 100,2,3,22,400 (b) garbage values (c) error (d) None 25. What is the output of the following code? #include<iostream.h> void main() { int a[5] = {1,2,3}; for(int i=0;i<5;i++) cout<<a[i]<<endl; } (a) No output (b) 1 2 3 garbage garbage (c) 1 2 3 0 0 (d) There is a run time error 26. To delete a dynamically allocated array named ‘a’, the correct statement is (a) delete a; (b) delete a[0]; (c) delete []a; (d) delete [0]a; 27. Which of the followings is not a valid assignment statement? (a) total = 9; (b) name = “CDAC”; (c) profit = 123.123; (d) A = ‘A’; 28. When do preprocessor directives execute? (a) Before the compiler compiles the program. (b) After the compiler compiles the program. (c) At the same time as the compiler compiles the program. (d) None 29. What is the output of the following code? #include<iostream.h> void main() { int i=5,j=0; while(i-- || j++) { cout<<i<<" "<<j<<”,”; } } (a) 5 1, 4 2, 3 3, 2 4, 1 5, (b) 4 0, 3 0, 2 0, 1 0, 0 0, (c) 4 1, 3 2, 2 3, 1 4, 0 5, (d) None 30. What is the output of the following code? #include<iostream.h> void main() { int a; bool b; a = 12 > 100; b = 12 >= 100; cout<<a<<" "<<b<<endl; } (a) Error (b) 0 false (c) 0 1 (d) 0 0 36. What is the output of the following code if user enters “This is a test”? #include<iostream.h> #include<string.h> void main() { char str[8]; cin>>str; cout<<str; } (a) This is a test (b) This is a (c) This (d) Error 37. What is the output of the following code? #include<iostream.h> void main() { int arr[] = {10,20,30,40,50}; int *ptr = arr; cout<< *ptr++<<" "<<*ptr; } (a) 10 20 (b) 10 10 (c) 20 20 (d) 20 10 38. What is the output of the following code? #include<iostream.h> void main() { int arr[] = {10,20,30,40,50}; int x,*ptr1 = arr, *ptr2=&arr[3]; x = ptr2 - ptr1; } cout<<x; (c) Compile Time error (d) Runtime Error (a) 6 (b) 3 39. Which of the following statement is false about pointers? (a) The ++ and -- operators may be used with pointer variables (b) An integer may be added and subtracted from a pointer variable (c) A pointer may be added to another pointer. (d) A pointer may be subtracted from another pointer. 40. A null pointer is a pointer that contains (a) the address 0 (b) the address that points to 0 (c) the address that points to ‘\0’ (d) the address that points to -1 41. What is the output of the following code? #include<iostream.h> void main() { int arr[][3]={0,11,22,33,44,55}; int *a = &arr[0][0]; cout<<arr[1][2]<<" "<<*(a+3); } (a) 55 33 (b) 33 55 (c) Compile Time error (d) Runtime Error 42. What is the output of the following code? #include<iostream.h> void main() { int arr[2][3][2]={{{2,4},{7,8},{3,4},}, {{2,2},{2,3},{3,4}, }}; cout<<(*(*(*arr+1)+2)+0)+7; } (a) 10 (b) 3 (c) garbage value (d) Error 43. What is the output of the following code? #include<iostream.h> void main() { int arr[2][3][2]={{{2,4},{7,8},{3,4},}, {{2,2},{2,3},{3,4}, }}; cout<<**(*arr+1)+2+7; } (a) 16 (b) 7 (c) 11 (d) Error 44. The design of classes in a way that hides the details of implementation from the user is known as: (a) Encapsulation (b) Information Hiding (c) Data abstraction (d) All of the above 57. Which of the following can be virtual? (a) constructors (b) destructors (c) static functions (d) None of the above 58. Where is an exception generated? (a) In the catch block (b) In the throw clause (c) In the constructor of a class (d) Only when memory allocation fails. 59. Static member functions (a) can be used without an instantiation of an object. (b) can only access static data. (c) Both 1 and 2 are correct. (d) Neither 1 nor 2 are correct. 60. What makes a class abstract? (a) The class must not have method (b) The class must have a constructor that takes no arguments (c) The class must have a function definition equal to zero (d) The class may only exist during the planning phase 61. #include<iostream.h> class Base { int static i; public: Base(){} }; class Sub1: public virtual Base{}; class Sub2: public Base{}; class Multi: public Sub1, public Sub2 {}; void main() { Multi m; } In the above program, how many times Base’s constructor will be called? (a) 1 (b) 2 (c) 3 (d) none 62. #include<iostream.h> namespace N1 { int f(int n) {return n*2;} } namespace N2 { int f(double n) {return n*3;} } void main() { using N1::f; int i1=f(1.0); using N2::f; int i2=f(1.0); } In the above code what would be the values of i1 and i2 (a) i1=2 i2=2 (b) i1=2 i2=3 (c) i1=3 i2=2 (d) Error 63. #include<iostream.h> class Base { public : int a; protected: int b; private: int c; }; class Derived: Base { int d; friend Friend; }; class Friend { Derived derived; }; In the above code, which of the following variables can be accessed in "Friend"? (a) only a and b (b) a,b and c (c) only a (d) Error 64. What is the output of the following code? #include<iostream.h> int main() { Base *pb = new Derived(); return 0; } (a) There is nothing wrong (b) One cannot have a ‘Base’ pointer to ‘Derived’ since it is not derived publicly (c) One need a derived class pointer to point to a derived class. (d) One required to code a constructor for Derived. 68.What is the output of the following code? #include<iostream.h> class professor{public:professor(){cout<<"professor ";};}; class researcher{public: researcher(){cout<<"researcher ";};}; class teacher: public professor{public: teacher(){cout<<"teacher ";};}; class myprofessor: public teacher, public virtual researcher {public:myprofessor(){cout<<"myprofessor ";};}; int main() { myprofessor obj; return 0; } (a) professor researcher teacher myprofessor (b) researcher professor teacher myprofessor (c) myprofessor teacher researcher professor (d) myprofessor researcher professor teacher 69. What is the output of the following code? #include<iostream.h> class Parent { public: Parent(){Status();} virtual ~Parent() { Status();} virtual void Status(){cout<<"Parent ";} }; class Child: public Parent { public: Child(){Status();} virtual ~Child() { Status();} virtual void Status(){cout<<"Child ";} }; void main() { Child c; } (a) Parent Parent (b) Parent Child Child Parent (c) Child Parent Parent Child (d) Error 70. What is wrong in the following code? #include<iostream.h> class Base { public: virtual void Method()=0{n=1;} private: int n; }; class D1:Base {}; class D2:public D1 { int i; void Method(){i=2;} }; int main() { D2 test; return 0; } (a) There is no error. (b) There is a syntax error in the declaration of “Method”. (c) Class D2 does not have access to “Method”. (d) Class D1 must define “Method”.