Академический Документы
Профессиональный Документы
Культура Документы
1. What is C language?
C is a programming language developed at AT & T's Bell Laboratories of USA in 1972.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
2. What are the types of constants in c?
C constants can be divided into two categories :
Primary constants
Secondary constants
3. What are the types of C intructions?
Now that we have written a few programs let us look at the instructions that we used
in these programs. There are basically three types of instructions in C :
Type Declaration Instruction
Arithmetic Instruction
Control Instruction
4. What is a pointer?
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.
5. What is the difference between arrays and pointers?
Pointers are used to manipulate data using the address. Pointers use operator to access the
data pointed to by them.
Arrays is a collection of similar datatype. Array use subscripted variables to access and
manipulate data. Array variables can be Equivalently written using pointer expression.
12345
6. What is thiss pointer?
The this pointer is a pointer accessible only within the member functions of a class, struct, or
union type. It points to the object for which the member function is called. Static member
functions do not have a this pointer.
The main difference between an array and a list is how they internally store the data.
whereas Array is collection of homogeneous elements. List is collection of heterogeneous
elements.
34. What is encapsulation?
Containing and hiding information about an object, such as internal data structures and
code. Encapsulation isolates the internal complexity of an objects operation from the rest of
the application.
35. What is a pointer variable?
A pointer variable is a variable that may contain the address of another variable or any valid
address in the memory.
36. What is the difference between a string copy (strcpy) and a memory copy (memcpy)?
The strcpy() function is designed to work exclusively with strings. It copies each byte of the
source string to the destination string and stops when the terminating null character () has
been moved.
On the other hand, the memcpy() function is designed to work with any type of data.
Because not all data ends with a null character, you must provide the memcpy() function
with the number of bytes you want to copy from the source to the destination.
37. What is the difference between a NULL Pointer and a NULL Macro?
Null pointer is a pointer that is pointing nothing while NULL macro will used for replacing
0 in program as #define NULL 0 .
38. What is the difference between const char*p and char const* p?
const char*p - p is pointer to the constant character. i.e value in that address location is
constant.
const char* const p - p is the constant pointer which points to the constant string, both value
and address are constants.
39. What is the purpose of realloc()?
Realloc(ptr,n) function uses two arguments.
The first argument ptr is a pointer to a block of memory
for which the size is to be altered.
The second argument n specifies the new size.The size
may be increased or decreased.
62. What are macros? What are its advantages and disadvantages?
Macros are abbreviations for lengthy and frequently used statements. When a macro is
called the entire code is substituted by a single line though the macro definition is of several
lines.
The advantage of macro is that it reduces the time taken for control transfer as in case of
function.
The disadvantage of it is here the entire code is substituted so the program becomes lengthy
if a macro is called several times.
63. What is a copy constructor and when is it called?
A copy constructor is a method that accepts an object of the same class and copies it
members to the object on the left part of assignement.
64. Where is the auto variables stored?
Auto variables can be stored anywhere, so long as recursion works. Practically,
theyrestored on the stack. It is not necessary that always a stack exist. You could
theoretically allocate function invocation records from the heap.
65. What is the difference between arrays and linked list?
An array is a repeated pattern of variables in contiguous storage. A linked list is a set of
structures scattered through memory, held together by pointers in each element that point to
the next element. With an array, we can (on most architectures) move from one element to
the next by adding a fixed constant to the integer value of the pointer. With a linked list,
there is a next pointer in each structure which says what element comes next.
66. What are register variables? What are the advantages of using register variables?
If a variable is declared with a register storage class,it is known as register variable.The
register variable is stored in the cpu register instead of main memory.Frequently used
variables are declared as register variable as its access time is faster.
67. What is problem with Runtime type identification?
The run time type identification comes at a cost of performance penalty. Compiler maintains
the class.
68. What is conversion operator?
You can define a member function of a class, called a conversion function, that converts
from the type of its class to another specified type.
In C void* acts as a generic pointer. When other pointer types are assigned to generic
pointer,conversions are applied automatically (implicit conversion).
77. How pointer variables are initialized?
Pointer variables are initialized by one of the following ways.
Static memory allocation
Dynamic memory allocation
78. What are the advantages of auto variables?
The same auto variable name can be used in different
blocks.
There is no side effect by changing the values in the
blocks.
The memory is economically used.
Auto variables have inlierent protection because of
local scope.
79. What is dynamic memory allocation?
A dynamic memory allocation uses functions such as malloc() or calloc() to get memory
dynamically. If these functions are used to get memory dynamically and the values returned
by these function are assigned to pointer variables, such a way of allocating memory at run
time is known as dynamic memory allocation.
80. What is the purpose of realloc?
It increases or decreases the size of dynamically allocated array. The function realloc (ptr,n)
uses two arguments. The first argument ptr is a pointer to a block of memory for which the
size is to be altered. The second argument specifies the new size. The size may be increased
or decreased. If sufficient space is not available to the old region the function may create a
new region.
81. What is pointer to a pointer?
If a pointer variable points another pointer value. Such a situation is known as a pointer to a
pointer.
Example : int *p1,
**p2,
v=10;P1=&v; p2=&p1;
Here p2 is a pointer to a pointer.
82. What is the difference between linker and linkage?
Linker converts an object code into an executable code by linking together the necessary
built in functions. The form and place of declaration where the variable is declared in a
program determine the linkage of variable.
83. What is a function?
A large program is subdivided into a number of smaller programs or subprograms. Each
subprogram specifies one or more actions to be performed for the larger program. Such sub
programs are called functions.
84. What is an argument?
An argument is an entity used to pass data from the calling to a called function.
85. What are built in functions?
The functions that are predefined and supplied along with the compiler are known as built in
functions. They are also known as library functions.
86. Can a Structure contain a Pointer to itself?
Yes such structures are called self-referential structures.
87. What is the difference between array and pointer?
Array
Array allocates space automatically.
It cannot be resized
It cannot be reassigned.
size of (arrayname) gives the number of bytes occupied
by the array.
Pointer
Explicitly assigned to point to an allocated space.
It can be sized using realloc() 3-pointer can be
reassigned.
sizeof (p) returns the number of bytes used to store the
pointer variable p.
88. What is the difference between syntax vs logical error?
Syntax Error
These involves validation of syntax of language.
main()
{
char *p1=name;
char *p2;
p2=(char*)malloc(20);
memset (p2, 0, 20);
while(*p2++ = *p1++);
printf(%sn,p2);
}
Answer:empty string.
1.
main()
{
int x=20,y=35;
x=y++ + x++;
y= ++y + ++x;
printf(%d%dn,x,y);
}
Answer : 5794
1.
main()
{
int x=5;
printf(%d,%d,%dn,x,x< <2,x>>2);
}
Answer: 5,20,1
1.
printf(%d %dn,x,y);
}
int swap2(int a, int b)
{
int temp;
temp=a;
b=a;
a=temp;
return 0;
}
Answer: 10, 5
10, 5
1.
main()
{
char *ptr = Cisco Systems;
*ptr++; printf(%sn,ptr);
ptr++;
printf(%sn,ptr);
}
Answer:Cisco Systems
isco systems
1.
main()
{
char s1[]=Cisco;
char s2[]= systems;
printf(%s,s1);
}
Answer: Cisco
1.
main()
{
char *p1;
char *p2;
p1=(char *)malloc(25);
p2=(char *)malloc(25);
strcpy(p1,Cisco);
strcpy(p2,systems);
strcat(p1,p2);
printf(%s,p1);
}
Answer: Ciscosystems
1.
The following variable is available in file1.c, who can
access it?:
9. static int average;
Answer: all the functions in the file1.c can access the variable.
1.
int x;
int modifyvalue()
{
return(x+=10);
}
int changevalue(int x)
{
return(x+=1);
}
void main()
{
int x=10;
x++;
changevalue(x);
x++;
modifyvalue();
printf("First output:%dn",x);
x++;
changevalue(x);
printf("Second output:%dn",x);
modifyvalue();
printf("Third output:%dn",x);
}
Answer: 12 , 13 , 13
1.
main()
{
int x=10, y=15;
x = x++;
y = ++y;
printf(%d %dn,x,y);
}
Answer: 11, 16
1.
main()
{
int a=0;
if(a==0)
printf(Cisco Systemsn);
printf(Cisco Systemsn);
}
Answer: Two lines with Cisco Systems will be printed.
What is inheritance?
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.
What is destructor?
Destructor usually deletes any extra resources allocated by the
object.
...
delete []my_ints;
What is reference ??
reference is a name that acts as an alias, or alternative name,
for a previously defined variable or an object.
prepending variable with "&" symbol makes it as reference.
for example:
int a;
int &b = a;
with two byte alignment has a zero in the least significant bit.
And a pointer with four byte alignment has a zero in both the two
least significant bits. And so on. More alignment means a longer
sequence of zero bits in the lowest bits of a pointer.
What is overloading??
With the C++ language, you can overload functions and operators.
Overloading is the practice of supplying more than one definition
for a given function name in the same scope.
- Any two functions in a set of overloaded functions must have
different argument lists.
What is Overriding?
To override a method, a subclass of the class that originally
declared the method must declare a method with the same name,
return type (or a subclass of that return type), and same
parameter list.
The definition of the method overriding is:
Must have same method name.
Must have same data type.
Must have same argument list.
Overriding a method means that replacing a method functionality
in child class. To imply overriding functionality we need parent
and child classes. In the child class you define the same method
signature as one defined in the parent class.
if someone will derive from your class, and if someone will say
"new Derived", where "Derived" is derived from your class, and if
someone will say delete p, where the actual object's type is
"Derived" but the pointer p's type is your class.
Can you think of a situation where your program would crash
without reaching the breakpoint which you set at the beginning of
main()?
C++ allows for dynamic initialization of global variables before
main() is invoked. It is possible that initialization of global
will invoke some function. If this function crashes the crash
will occur before main() is entered.
::