Wednesday, May 2, 2007

Campus_4 (C,C++ questions)

Q: How many ways are there to initialize an int with a constant?
A: There are two formats for initializers in C++ as shown in the example that follows. The first format uses the traditional C notation. The second format uses constructor notation.int foo = 123;int bar (123);

Q: Explain the scope resolution operator.
A: It permits a program to reference an identifier in the global scope that has been hidden by another identifier with the same name in the local scope.
The answer can get complicated. However, it should start with “::”. If the programmer is well into the design or use of classes that employ inheritance you might hear a lot about overriding member function overrides to explicitly call a function higher in the hierarchy. That’s good to know, but ask specifically about global scope resolution. You’re looking for a description of C++’s ability to override the particular C behavior where identifiers in the global scope are always hidden by like identifiers in a local scope.

Q: In C, why is the void pointer useful? When would you use it?
A: The void pointer is useful because it is a generic pointer that any pointer can be cast into and back again without loss of information.

Q: In C, what is the difference between a static variable and global variable?
A: A static variable declared outside of any function is accessible only to all the functions defined in the same file (as the static variable). However, a global variable can be accessed by any function (including the ones from different files).

Q: In C++, what is the difference between method overloading and method overriding?
A: Overloading a method (or function) in C++ is the ability for functions of the same name to be defined as long as these methods have different signatures (different set of parameters). Method overriding is the ability of the inherited class rewriting the virtual method of the base class.

Q: What is pure virtual function?
A: A class is made abstract by declaring one or more of its virtual functions to be pure. A pure virtual function is one with an initializer of = 0 in its declaration.

Q: What is a virtual destructor?
A: The simple answer is that a virtual destructor is one that is declared with the virtual attribute. The behavior of a virtual destructor is what is important. If you destroy an object through a pointer or reference to a base class, and the base-class destructor is not virtual, the derived-class destructors are not executed, and the destruction might not be complete.

Q: What is virtual channel?
A: Virtual channel is normally a connection from one source to one destination, although multicast connections are also permitted. The other name for virtual channel is virtual circuit.

Q: You have one base class virtual function how will call that function from derived class?
A: class a{public virtual int m(){return 1;}}
class b:a{public int j(){return m();}}

Q: Write a function that will reverse a string.
A: char *strrev(char *s)
{
int i = 0,
len = strlen(s);
char *str;
if ((str = (char *)malloc(len+1)) == NULL) /*cannot allocate memory */
err_num = 2;return (str);
}
while(len)str[i++]=s[?len];
str[i] = NULL;return (str);
}

5 comments:

tvldummy said...

Find more questions answers from http://www.indiabix.com/c-programming/index.php

tvldummy said...

Find more questions answers from http://www.indiabix.com/c-programming/index.php

C Programming Questions

Karthik said...

More aptitude, verbal and logical reasoning mock exams and questions at http://skillrack.com/freetest.jsf

arif khan said...

I was very pleased to find this site. I wanted to thank you for this great read!! I definitely enjoying every little bit of it and I have you bookmarked to check out new stuff you post. Big thanks for the useful info

Unknown said...

Hello There,


Great piece on Campus_4 (C,C++ questions) I’m a fan of the ‘flowery’ style Looking forward to more long form articles ??

I am trying to make a program in C with multiple bouncing balls. I know it is a very known program and I have already searched the internet and seen different versions of it. However, because I am new in programming, I didn’t manage to understand them and answer my questions The problem is that I have created a code, but my program doesn’t run properly. To be more exact, I think the part where it reads the data is fine, but then there is a problem in the code of the graphics' library. I cannot understand where the problem is, as it is the first time I use this library.


Super likes !!! for this amazing post. I thinks everyone should bookmark this.


Grazie,
Samson