Saturday 6 April 2013

What is a structure?

What is a structure?

Ans: Structure constitutes a super data type which represents several different data types in a single unit. A structure can be initialized if it is static or global.




Blog Author: Vijay Kumar

What are the uses of a pointer?

What are the uses of a pointer?

Ans: Pointer is used in the following cases
i) It is used to access array elements
ii) It is used for dynamic memory allocation.
iii) It is used in Call by reference
iv) It is used in data structures like trees, graph, linked list etc.



Blog Author: Vijay Kumar

What is a pointer?


What is a pointer?

Ans: Pointers are variables which stores the address of another variable. That variable may be a scalar (including another pointer), or an aggregate (array or structure). The pointed-to object may be part of a larger object, such as a field of a structure or an element in an array.


What does static variable mean?

What does static variable mean?

Ans: Static variables are the variables which retain their values between the function calls. They are initialized only once their scope is within the function in which they are defined.




Blog Author: Vijay Kumar

What is the output of printf("%d")?


What is the output of printf("%d")?
1. When we write printf("%d",x); this means compiler will print the
value of x. But as here, there is nothing after %d so compiler will show
in output window garbage value.
2. When we use %d the compiler internally uses it to access the
argument in the stack (argument stack). Ideally compiler determines
the offset of the data variable depending on the format specification
string. Now when we write printf("%d",a) then compiler first accesses
the top most element in the argument stack of the printf which is %d
and depending on the format string it calculated to offset to the actual
data variable in the memory which is to be printed. Now when only %d
will be present in the printf then compiler will calculate the correct
offset (which will be the offset to access the integer variable) but as
the actual data object is to be printed is not present at that memory
location so it will print what ever will be the contents of that memory
location.
3. Some compilers check the format string and will generate an error
without the proper number and type of arguments for things like
printf(...) and scanf(...).


What is C language?


What is C language?
The C programming language is a standardized programming language
developed in the early 1970s by Ken Thompson and Dennis Ritchie for
use  on  the  UNIX operating system.  It  has since  spread  to many  other
operating   systems,   and  is  one  of  the  most   widely  used  programming
languages.   C   is   prized   for   its   efficiency,   and   is   the   most   popular
programming   language  for   writing  system  software,   though  it  is  also
used for writing applications.


What is encapsulation??

What is encapsulation??

Containing and hiding information about an object, such as internal data structures and code. Encapsulation isolates the internal complexity of an object's operation from the rest of the application. For example, a client component asking for net revenue from a business object need not know the data's origin.




Blog Author: Vijay Kumar

What is inheritance?

What is inheritance?

Inheritance allows one class to reuse the state and behavior of another class. The derived class inherits the properties and method implementations of the base class and extends it by overriding methods and adding additional properties and methods.




Blog Author: Vijay Kumar

What is Polymorphism??

What is Polymorphism??

Polymorphism allows a client to treat different objects in the same way even if they were created from different classes and exhibit different behaviors.
You can use implementation inheritance to achieve polymorphism in languages such as C++ and Java.
Base class object's pointer can invoke methods in derived class objects.
You can also achieve polymorphism in C++ by function overloading and operator overloading.




Blog Author: Vijay Kumar

What is constructor or ctor?

What is constructor or ctor?

Constructor creates an object and initializes it. It also creates vtable for virtual functions. It is different from other methods in a class.




Blog Author: Vijay Kumar

What is destructor?

What is destructor?

Destructor usually deletes any extra resources allocated by the object.




Blog Author: Vijay Kumar

What is default constructor?

What is default constructor?

Constructor with no arguments or all the arguments has default values.




Blog Author: Vijay Kumar

What are C++ storage classes?

What are C++ storage classes?

auto
register
static
extern


auto: the default. Variables are automatically created and initialized when they are defined and are destroyed at the end of the block containing their definition. They are not visible outside that block
register: a type of auto variable. a suggestion to the compiler to use a CPU register for performance
static: a variable that is known only in the function that contains its definition but is never destroyed and retains its value between calls to that function. It exists from the time the program begins execution
extern: a static variable whose definition and placement is determined when all object and library modules are combined (linked) to form the executable code file. It can be visible outside the file where it is defined.




Blog Author: Vijay Kumar

What are storage qualifiers in C++ ?

What are storage qualifiers in C++ ?

They are..
const
volatile
mutable
Const keyword indicates that memory once initialized, should not be altered by a program.
volatile keyword indicates that the value in the memory location can be altered even though nothing in the program
code modifies the contents. for example if you have a pointer to hardware location that contains the time, where hardware changes the value of this pointer variable and not the program. The intent of this keyword to improve the optimization ability of the compiler.  
mutable keyword indicates that particular member of a structure or class can be altered even if a particular structure variable, class, or class member function is constant.
struct data
{
char name[80];
mutable double salary;
}
const data MyStruct = { "Satish Shetty", 1000 }; //initlized by complier
strcpy ( MyStruct.name, "Shilpa Shetty"); // compiler error
MyStruct.salaray = 2000 ; // complier is happy allowed



Blog Author: Vijay Kumar