Monday, 25 April 2011

C++ INTERVIEW QUESTIONS


What is the diffrence between c# and c+?

c is procedure oriented language&c++is object oriented language.
 

Read the following program carefully and write the output of the program. Explain each line of code according to given numbering. #include <stdio.h> #include <unistd.h> #include <stdlib.h> #include <errno.h> 1……………… int main (void) { pid_t pid; 2………………………… pid = fork(); 3…………………………. if (pid > 0) { int i; 4………………………… for (i = 0; i < 5; i++) { 5………………… …………… printf(" I AM VU : %d\n", i); 6………………… …………… sleep(1); } exit(0); } 7………………… ……… else if (pid == 0) { int j; for (j = 0; j < 5; j++) { 8……………………………… printf(" I have no child: %d\n", j); sleep(1); } _exit(0); } else { 9………………………………fprintf(stderr, "can't fork, error %d\n", errno); 10……………… … ………… exit (EXIT_FAILURE); } ?

1 int main (void) Starts the main function 
2 pid = fork ( ); The fork ( ) method will call and store 
the integer value in the pid variable. In case of Child “0” 
value returned while the parent will store the “process id” 
of the child. In case when fork fails it will be 
initialized by -1 
3 if (pid > 0) This condition will be only true when fork 
failed. 
4 for (i = 0; i < 5; i++) Limmitations of for loop are 
declared and the loop starts 
5 printf(" I AM VU : %d\n", i); 
Prints I AM VU and the value of I message on screen 
6 sleep(1); Process sleeps 
7 else if (pid == 0) Now this blok of code executes in 
parent process since fork returns the ID to the parent 
process from child. which is not 0. 
8 printf(" I have no child: %d\n", j); 
“I have no child” is printed on the screen 
9 fprintf(stderr, "can't fork, error %d\n", errno); 
If the given conditions are not true then this error 
message is send 
10 exit (EXIT_FAILURE); system call will terminate the 
process abnormally as it fails.

1 1 2 1 2 3 1 2 3 4 1 2 3 1 2 1 generate this output using for loop?

#include<conio.h>
#include<stdio.h>
void main()
{
int i,j,k,l;
for(i=1;i<=4;i++)
{
 for(k=i;k<=4;k++)
 {
  printf(" ");
 }
 for(j=1;j<=i;j++)
 {
  printf(" %d",j);
 }
printf("\n");
}
for(i=3;i>0;i--)
 {
 for(l=i;l<=3;l++)
  {
  printf(" ");
  }
 for(j=1;j<=i;j++)
  {
  printf(" %d",j);
  }
 printf("\n");
 }
getch();

What’s the advantage of using System.Text.StringBuilder over System.String? 
StringBuilder is more efficient in the cases, where a lot of manipulation is done to the text. Strings are immutable, so each time it’s being operated on, a new instance is created.
Can you store multiple data types in System.Array?
 No.
What’s the difference between the System.Array.CopyTo() and System.Array.Clone()?
 The first one performs a deep copy of the array, the second one is shallow.
How can you sort the elements of the array in descending order? 
By calling Sort() and then Reverse() methods.
What’s the .NET datatype that allows the retrieval of data by a unique key?
 HashTable.
What’s class SortedList underneath? 
A sorted HashTable.
Will finally block get executed if the exception had not occurred? 
Yes.
What’s the C# equivalent of C++ catch (…), which was a catch-all statement for any possible exception?
 A catch block that catches the exception of type System.Exception. You can also omit the parameter data type in this case and just write catch {}.
Can multiple catch blocks be executed? 
No, once the proper catch code fires off, the control is transferred to the finally block (if there are any), and then whatever follows the finally block.
Why is it a bad idea to throw your own exceptions? 
Well, if at that point you know that an error has occurred, then why not write the proper code to handle that error instead of passing a new Exception object to the catch block? Throwing your own exceptions signifies some design flaws in the project.
What’s a delegate? 
A delegate object encapsulates a reference to a method. In C++ they were referred to as function pointers.
What’s a multicast delegate? 
It’s a delegate that points to and eventually fires off several methods.
How’s the DLL Hell problem solved in .NET? 
Assembly versioning allows the application to specify not only the library it needs to run (which was available under Win32), but also the version of the assembly

What are the ways to deploy an assembly? 
An MSI installer, a CAB archive, and XCOPY command.
 
 

2 comments:

  1. Nice tutorial. Thanks for sharing the valuable info about c Training. it’s really helpful. Who want to learn c language this blog most helpful. Keep sharing on updated tutorials…..

    ReplyDelete