CS201 Midterm Short Notes and Subjectives Question and Answer
CS201 Midterm Short Notes and Subjectives Question and Answer
CS201 Midterm Short Notes and Subjectives Question and Answer
com
CS201-Imtroduction to Programming-Short Notes
The C++ programming language has a history going back to 1979, when Bjarne Stroustrup was doing
work for his Ph.D. thesis. One of the languages Stroustrup had the opportunity to work with was a
language called Simula, which as the name implies is a language primarily designed for simulations.
Bloodshed Dev-C++ is a full-featured Integrated Development Environment (IDE) for the C/C++
programming language. It uses Mingw port of GCC (GNU Compiler Collection) as it's compiler. Dev-C++
can also be used in combination with Cygwin or any other GCC based compiler.
Dev-C++ is a free IDE for Windows that uses either MinGW or TDM-GCC as underlying compiler.
Originally released by Bloodshed Software, but abandoned in 2006, it has recently been forked by
Orwell, including a choice of more recent compilers.
Many programming languages and other computer files have a directive, often called include (as well as
copy and import), that causes the contents of a second file to be inserted into the original file. These
included files are called copybooks or header files.
Curly braces are used to group a set of statements. Often we use them along with loops and conditional
statements in order to avoid confusion and to define a clear scope.
In C, the "main" function is treated the same as every function, it has a return type (and in some cases
accepts inputs via parameters). The only difference is that the main function is "called" by the operating
system when the user runs the program.
www.VUAnswer.com
www.VUAnswer.com
Int or signed int unsigned int, short int or signed short int, long int or signed long int, unsigned long int
The built in C++ library routines are kept in the standard namespace. That includes stuff like cout, cin,
string, vector, map, etc. Because these tools are used so commonly, it's popular to add "using
namespace std" at the top of your source code so that you won't have to type the std:: prefix constantly.
The Syntax of Declare variable is data_type variable_name; where the data_type is the type of data
which can hold a variable variable_name might be anything except the C directives and reserve words.
Consider a situation, when we have two persons with the same name, Zara, in the same class. Whenever
we need to differentiate them definitely we would have to use some additional information along with
their name, like either the area if they live in different area or their mother or father name, etc. Same
www.VUAnswer.com
www.VUAnswer.com
situation can arise in your C++ applications. For example, you might be writing some code that has a
function called xyz() and there is another library available which is also having same function xyz(). Now
the compiler has no way of knowing which version of xyz() function you are referring to within your
code.A namespace is designed to overcome this difficulty and is used as additional information to
differentiate similar functions, classes, variables etc. with the same name available in different libraries.
Using namespace, you can define the context in which names are defined. In essence, a namespace
defines a scope.
A namespace definition begins with the keyword namespace followed by the namespace name as
follows
namespacenamespace_name {
// code declarations
To call the namespace-enabled version of either function or variable, prepend the namespace name as
follows:
Reserve or Keywords are the words that C language use for his personal use a user cannot use reserve
words as variable, function or class name. Example: IF, Else, Switch, For, While, Float etc.
3. Except underscore (_) no other special symbol are allowed in the middle of the variable
declaration.
www.VUAnswer.com
www.VUAnswer.com
4. Maximum length of variable is 8 characters depend on compiler and operation system.
5. Every variable name always should exist in the left hand side of assignment operator.
For a variable, a definition is a declaration which allocates storage for that variable.
Initialization is the specification of the initial value to be stored in an object, which is not necessarily the
same as the first time you explicitly assign a value to it.
cout is used for output, cin for input. Cout and cin are not key words in the C++ language. They are
variables, instances of classes that have been declared in <iostream>.
Variables that are declared inside a function or block are local variables. They can be used only by
statements that are inside that function or block of code. Local variables are not known to functions
outside their own.Global variables are defined outside of all the functions, usually on top of the
program. The global variables will hold their value throughout the life-time of your program. A global
variable can be accessed by any function. That is, a global variable is available for use throughout your
entire program after its declaration.
Asyntax error is an error in the syntax of a sequence of characters or tokens that is intended to be
written in a particular programming language. For compiled languages, syntax errors are detected at
compile-time. A program will not compile until all syntax errors are corrected.
An error that occurs during the execution of a program. In contrast, compile-time errors occur while a
program is being compiled. Runtime errors indicate bugs in the program or problems that the designers
had anticipated but could do nothing about. For example, running out of memory will often cause a
runtime error.
A logic error is a bug in a program that causes it to operate incorrectly, but not to terminate abnormally
(or crash). A logic error produces unintended or undesired output or other behavior, although it may not
immediately be recognized as such.
www.VUAnswer.com
www.VUAnswer.com
24. What are arithmetic operators?
C language has 5 arithmetic operators (+, -, *, /, %). Arithmetic operators are used to perform arithmetic
operations in c programming.
&& Called Logical AND operator. If both the operands are non-zero, then the condition becomes
true. (A && B) is false.
|| Called Logical OR Operator. If any of the two operands is non-zero, then the condition becomes
true. (A || B) is true.
! Called Logical NOT Operator. It is used to reverse the logical state of its operand. If a condition is
true, then Logical NOT operator will make it false. ! (A && B) is true.
A ternary operator or Conditional Operator is an operator that takes three arguments. The arguments
and result can be of different types. Many programming languages that use C-like syntax feature a
ternary operator, ?:, which defines a conditional expression. Since this operator is often the only existing
ternary operator in the language, it is sometimes simply referred to as "the ternary operator". In some
languages, this operator is referred to as "the conditional operator". Another example for a ternary
operator is between, as used in SQL and Python.
Operands are the objects that are manipulated and operators are the symbols that represent specific
actions. For example, in the expression. 5 + x. and 5 are operands and + is an operator. All expressions
have at least one operand.
ofstream This data type represents the output file stream and is used to create files and to write
information to files.
ifstream This data type represents the input file stream and is used to read information from
files.
www.VUAnswer.com
www.VUAnswer.com
fstream This data type represents the file stream generally, and has the capabilities of both ofstream and
ifstream which means it can create files, write information to files, and read information from files.
In computer science, conditional statements, conditional expressions and conditional constructs are
features of a programming language, which perform different computations or actions depending on
whether a programmer-specified Boolean condition evaluates to true or false. Example: IF. Then, Switch.
In C programming Language it is often necessary to repeat the same block of code a given number of
times, or until a certain condition is met. Executes a sequence of statements multiple times and
abbreviates the code that manages the loop variable. You can use one or more loops inside any other
while, for, or do. While loop.
In C++ we can use if statement in the else block. Or we can also include if block in another if block, it’s
called nested IF. The placing of one loop inside the body of another loop is called nesting. When you
"nest" two loops, the outer loop takes control of the number of complete repetitions of the inner loop.
While all types of loops may be nested, the most commonly nested loops are for loops.
The C preprocessor modifies a source file before handing it over to the compiler, allowing conditional
compilation with #ifdef, defining constants with #define, including header files with #include.
This function use to copy string from one string variable to other string variable. Example strcpy(s1, s2)
copy string from s2 to s1.
A function is a group of statements that together perform a task. Every C program has at least one
function, which is main (), and all the most trivial programs can define additional functions. You can
divide up your code into separate functions.
In computer programming, a parameter is a special kind of variable, used in a subroutine to refer to one
of the pieces of data provided as input to the subroutine. These pieces of data are called arguments. An
www.VUAnswer.com
www.VUAnswer.com
ordered list of parameters is usually included in the definition of a subroutine, so that, each time the
subroutine is called, its arguments for that call can be assigned to the corresponding parameters.
The variable that stores the address of another variable is called a pointer. Pointers are a very powerful
feature of the language that has many uses in lower level programming.
Both are variables a pointer hold the memory address of a variable and an Variable that hold his value
both variable must be same type to work with each other.
A class in C++ is a user defined type or data structure declared with keyword class that has data and
functions (also called methods) as its members whose access is governed by the three access specifies
private, protected or public (by default access to members of a class is private).
Object is a class type variable. Objects are also called instance of the class. Each object contains all
members (variables and functions) declared in the class. We can access any data member or member
function from object of that class using. Operator.
40. How can we refer to the global variable if the local and the global variable names are same?
We can apply scope resolution operator :: for the scope of global variable. The scope resolution operator
helps to identify and specify the context to which an identifier refers, particularly by specifying a
namespace. The specific uses vary across different programming languages with the notions of scoping.
In many languages the scope resolution operator is written "::".
Recursion is the process of repeating items in a self-similar way. In programming languages, if a program
allows you to call a function inside the same function, then it is called a recursive call of the function.
An Identifier can only have alphanumeric characters (a-z, A-Z, 0-9) and underscore (_). The first
character of an identifier can only contain alphabet (a-z, A-Z) or underscore (_). Identifiers are also case
sensitive in C. For example name and Name are two different identifier in C.
www.VUAnswer.com
www.VUAnswer.com
Friend Function:A C++ friend functions are special functions which can access the private members of a
class. They are considered to be a loophole in the Object Oriented Programming concepts, but logical
use of them can make them useful in certain cases.
Friend Class: A C++ friend class is a special class that can access the members, objects and methods of
another class.
Constructor: A class constructor is a special member function of a class that is executed whenever we
create new objects of that class. A constructor will have exact same name as the class and it does not
have any return type at all, not even void. Constructors can be very useful for setting initial values for
certain member variables.
Destructors: A destructor is a special member function of a class that is executed whenever an object of
its class goes out of scope or whenever the delete expression is applied to a pointer to the object of that
class.A destructor will have exact same name as the class prefixed with a tilde (~) and it can neither
return a value nor can it take any parameters. Destructor can be very useful for releasing resources
before coming out of the program like closing files, releasing memories etc.
The parameters sent to the function at calling end are called as actual parameters while at the
46. What is difference between including the header file with-in angular braces <> and double
quotes “”?
If a header file is included with in <> then the compiler searches for the particular header file
Only with in the built in include path. If a header file is included with in “ “, then the compiler
Searches for the particular header file first in the current working directory, if not found then in the built
in include path
47. If a pointer is declared for a class, which operator can be used to access it?
Arrow operator (->) is used for accessing members of structure using pointer variable, whenever we
declare structure variable then member can be accessed using the dot operator. But when pointer to a
structure is used then arrow operator is used. Both dot and arrow operator serves same function to
access member of structure.
www.VUAnswer.com
www.VUAnswer.com
Function overloading (also method overloading) is a programming concept that allows programmers to
define two or more functions with the same name. Each function has a unique signature (or header),
which is derived from: function/procedure name. Number of arguments. Arguments' type.
49. Is it possible to have Virtual Constructor? If yes, how? If not, Why not possible?
There is nothing like Virtual Constructor. The Constructor can’t be virtual as the constructor
Is a code which is responsible for creating an instance of a class and it can’t be delegated to any other
object by virtual keyword mean.
A dangling pointer arises when you use the address of an object after its lifetime is over. This may occur
in situations like returning addresses of the automatic variables from a function orusing the address of
the memory block after it is freed.
A smart pointer is a C++ class that mimics a regular pointer in syntax and some semantics, but it does
more. Because smart pointers to different types of objects tend to have a lot of code in common, almost
all good-quality smart pointers in existence are template by the pointe type.
A reference must always refer to some object and, therefore, must always be initialized; pointers do not
have such restrictions. A pointer can be reassigned to point to different objectswhile a reference always
refers to an object with which it was initialized.
53. What is the difference between const char *myPointer and char *const myPointer?
Const char *myPointer is a non-constant pointer to constant data; while char *const myPointer is a
constant pointer to non-constant data.
www.VUAnswer.com