ALLInterview.com :: Home Page KalAajKal.com
 Advertise your Business Here     
Browse  |   Placement Papers  |   Company  |   Code Snippets  |   Certifications  |   Visa Questions
Post Question  |   Post Answer  |   My Panel  |   Search  |   Articles  |   Topics  |   ERRORS new
   Refer this Site  Refer This Site to Your Friends  Site Map  Bookmark this Site  Set it as your HomePage  Contact Us     Login  |  Sign Up                      
tip   SiteMap shows list of All Categories in this site.
Google
 
Categories >> Software >> Programming-Languages
 
  C (726)  C++ (457)  Delphi (508)  Programming-Languages-AllOther (219)
 


 

Back to Questions Page
 
Question
what is out put of the following code? 
#include
class Base
{
Base()
{
cout<<"constructor base";
}
~Base()
{
cout<<"destructor base";
}
}
class Derived:public Base
{
Derived()
{
cout<<"constructor derived";
}
~Derived()
{
cout<<"destructor derived";
}
}
void main()
{
Base *var=new Derived();
delete var;
}

Rank Answer Posted By  
 Question Submitted By :: Nazim
This Interview Question Asked @   Honeywell
I also faced this Question!!   © ALL Interview .com
Answer
error.
because, there is no header file.
and no ";" is given after the end of classes.
 
0
Pooja Sonawane
 
 
Answer
there is no include file iostream for cout
immproper ending for classes ';'
 
0
Anvesh
 
 
Question
Write a C function to search a number in the given list of 
numbers. donot use printf and scanf
Rank Answer Posted By  
 Question Submitted By :: Nazim
This Interview Question Asked @   Honeywell
I also faced this Question!!   © ALL Interview .com
Answer
#include<stdio.h>
#include<conio.h>
void main()
{
char a[]="enter the no. of terms tou are going to enter :";
char a1[100];
char n;
puts(a);
int flag=0;
n=getchar();
int n1;
n1=(int)n    /* type casting*/
   for(int i=0;i<n1;i++)
      {
    a[i]=getchar();
}
char a3[]="enter the number do you want to find :";
puts(a3);
char s;
  s=getchar();
int b=(int)s;
  for(i=0;i<n1;i++)
{
     if(b==(int)a[i])
flag=1;
   }
if(flag==1)
printf("number is found");
else 
printf("not found");
getch();
}
this was the logic suddenly striked me.......................
 
0
Vignesh1988i
 
 
 
Answer
very sorry yaar/.... i forgettenly used printf statements in
my before posts.......... i think this can be the logic...
if am not wrong..............

#include<stdio.h>
#include<conio.h>
void main()
{
char a[]="enter the no. of terms tou are going to enter :";
char a1[100];
char n;
puts(a);
int flag=0;
n=getchar();
int n1;
n1=(int)n    /* type casting*/
   for(int i=0;i<n1;i++)
      {
    a[i]=getchar();
}
char a3[]="enter the number do you want to find :";
puts(a3);
char s;
  s=getchar();
int b=(int)s;
  for(i=0;i<n1;i++)
{
     if(b==(int)a[i])
flag=1;
   }
if(flag==1)
{
char q[]="number is found";
puts(q);
}
else
{
char w[]="number not found";
puts(w);
}
getch();
}
 
0
Vignesh1988i
 
 
Answer
Dear... Vignesh... r u tested?
if tested..., on what Compiler...
 
0
Gg
 
 
Answer
ya..... sorry... it wont work... since getchar gets only one
character the time.... when we give 48... i will take 4 and
8 .. but not as 48.... sorry for posting it... a lesson i
have learnt
 
0
Vignesh1988i
 
 
Answer
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>

int main ( int argc, char* argv[] )
{
	int array [ 10 ] = { 546, 541, 128, 1027, 1000, 
10234, 657, 343, 111, 272 };
	char _variable [ 50 ];
	int _count = 0;
	int _value = 0;

	memset ( _variable, '\0', 50 );
	puts ("Enter the number to search: ");
	gets ( _variable );
	
	_value = atoi ( _variable );

	for ( _count = 0; _count < 10; _count++ ) {
		if ( array [ _count ] == _value ) {
			puts ("Search SUCCESSFUL");
			return ( 0 );
		}
	}
	puts ("Search NOT SUCCESSFUL");
	return ( 1 );
}

If u guys really want to check the given input is numeric, 
use isnumeric function defined in ctypes.h
 
0
Abdur Rab
 
 
Answer
sorry for the wrong information use isdigit(char)
 
0
Abdur
 
 
Question
If 4 digits number is input through the keyboard, Write a 
program to calculate sum of its 1st & 4th digit.
Rank Answer Posted By  
 Question Submitted By :: Ydw_10
I also faced this Question!!   © ALL Interview .com
Answer
#
#
void main()
{
int num,n1,n2,sum;
cout<<"enter a 4 digit no.";
cin>>num;
n1=num/1000;
n2=num%10;
sum=n1+n2;
cout<<"sum of 1st & 4th digit is"<<sum;
}
 
0
Bharghavi
 
 
Answer
#include<stdio.h>
main()
{
int n,n1,n4;
printf("Enter 4 digit number:");
scanf("%d",&n);
n4=n%10;
n1=n/100;
printf("\nResult=",(n1+n4));
getch();
}

 
0
Anvesh
 
 
Question
what is the code for getting the output as 
                     *
                     **
                     ***
Rank Answer Posted By  
 Question Submitted By :: Madhavan
This Interview Question Asked @   Caritor , Caritor
I also faced this Question!!   © ALL Interview .com
Answer
main()
{
printf("*\n**\n***);
}
OR
main()
{
int n,i;
while(n<3)
{
i=0;
while(i<=n)
{printf("*");i++;}
printf("\n); n++;
}
 
0
Anvesh
 
 
Answer
void main()
{
int i,j;
for(i=0;i<3;i++)
printf("\n");
for(j=0;j<i;j++)
printf("*");
}
 
0
Pooja Sonawane
 
 
Answer
# include <Stdio.h>
# include <conio.h>
# include <string.h>

void main()
{
	int j,i,n;

	scanf("%d",&n);

	for (i=0;i<=n;i++)
	{
		for(j=0;j<i;j++)
			printf("*");
		printf("\n");
    }

	getch();

}
 
0
Babitha
 
 
Answer
#include<stdio.h>
main()
{
int n,i=0,j=0;
printf("Enter an intger : ");//upto n nof *'s
scanf("%d",&n);
while(j<n)
        {
        for(i=0;i<=j;printf("*"),i++);
        printf("\n",j++);
        }
}
 
0
Gg
 
 
Question
how to swap two numbers in a linked list without exchanging 
the data but only the links?
Rank Answer Posted By  
 Question Submitted By :: Bharghavi
This Interview Question Asked @   Wipro
I also faced this Question!!   © ALL Interview .com
Answer
Suppose List contains 3 no. 10, 20, 30
try to exchange 10 and 20.
head points to 10.

temp = head;
head = head -> next;
temp -> next = head - next;
head -> next = temp;

I think it works..
 
0
Pavny
 
 
Answer
head points 20
head=head->link;
link->next;
link->head=head->next
 
0
Siva
 
 
Question
You are given a string which contains some special
characters. You also have set of special characters. You are
given other string (call it as pattern string). Your job is
to write a program to replace each special characters in
given string by pattern string. You are not allowed to
create new resulting string. You need to allocate some new
memory to given existing string but constraint is you can
only allocate memory one time. Allocate memory exactly what
you need not more not less.
Rank Answer Posted By  
 Question Submitted By :: Rajendra_ait
This Interview Question Asked @   Microsoft
I also faced this Question!!   © ALL Interview .com
Answer
#include <stdio.h>
#include <string.h>

/**
 * int copy ( char* str, char* _pattern_to_copy, int 
number_of_bytes_moved, int total_size_allocated, int 
diff_size )
 * @param str, the pointer from where the pattern starts
 * @param _pattern_to_copy, what needs to be placed insted 
of the pattern
 * @param number_of_bytes_moved, the number of bytes at 
which the pattern first appeared
 * @param total_size_allocated, the total size the space 
has been allocated (eliminating the space for NULL)
 * @param diff_size, the difference between the pattern and 
the string that needs to be replaced
 *
 */
int copy ( char* str, char* _pattern_to_replace, int 
number_of_bytes_moved, int total_size_allocated, int 
diff_size )
{
	int _loop = 0;

	/**
	 * Starting from end, move towards untill the 
pattern appears
	 * start point is array start + the 
number_of_bytes_moved (first apperance of the pattern)
	 * so the end point should be array end - 
number_of_bytes_moved (the last space before the NULL 
character
	 * move the array down to create space for the 
string to be replaced 
	 */
	for ( _loop = total_size_allocated; ( 
total_size_allocated - number_of_bytes_moved ) >  
diff_size; total_size_allocated-- )
	{
		str [ total_size_allocated - 
number_of_bytes_moved ] = str [ total_size_allocated - 
number_of_bytes_moved - diff_size ];
	}

	/**
	 * Replace the string on the pattern
	 * Use memcpy since it does not copy provide NULL 
by itself
	 */
	memcpy ( str, _pattern_to_replace, strlen ( 
_pattern_to_replace ) );

	return ( 0 );
}

int main ( int argc, char* argv [] )
{
	char* string_value = NULL;
	char pattern_to_replace [] = {"replacement"};
	char pattern_2b_replaced [] = {"#"};
	int _count = 0;
	char* _ptr = NULL;
	int alocation_size = 0;
	int number_of_bytes_moved = 0;
	int old_strlen = 0;

	/**
	 * Allocate the size to hold the orignal string
	 * copy the required string with the pattern
	 */
	string_value = ( char* ) malloc ( 26 * sizeof ( 
char ) );
	if ( NULL != string_value ) 
	{
		strcpy ( string_value, "Hi # of new # 
string by #" );
	}

	/**
	 * Count the number of occurences of the pattern.
	 */
	_ptr = string_value;
	while ( _ptr = strstr ( _ptr, 
pattern_2b_replaced ) )
	{
		_ptr += 1;
		_count++;
	}

	/**
	 * Calculate the size of the new string that needs 
to be accomadated
	 * the number of times the pattern occurs in the 
original string
	 */
	alocation_size = ( strlen ( pattern_to_replace ) - 
strlen ( pattern_2b_replaced ) ) * _count; // calculated 
size of new string
	alocation_size += strlen ( string_value ); 	
			          // add the size of old 
string
	old_strlen = strlen ( string_value ) + 1;	
				  // allocate space to 
store NULL

	/**
	 * Increase the space in the old pointer using 
realloc
	 * and copy '&' in the newly allocated spaces alone
	 * just for the sake of our reference.
	 *
	 * Remember to exclude the 1 which we allocated for 
the NULL character
	 */
	string_value = ( char* ) realloc ( string_value, ( 
alocation_size * sizeof ( char ) ) );
	memset ( ( string_value + old_strlen) , '&', ( 
alocation_size - old_strlen - 1 ) );

	/**
	 * Store the NULL at the end of the total allocated 
size
	 * we use alocation_size - 1
	 * 
	 * eg: a[5] means 6th location in the array
	 * If we want to store at the 6th location 
	 * we need to provide 5 (ie. alocation_size - 1)
	 */
	string_value [ alocation_size - 1 ] = '\0';

	/**
	 * Replace the string needs to be filled
	 */
	_ptr = string_value;
	while ( _ptr = strstr ( _ptr, 
pattern_2b_replaced ) )
	{
		number_of_bytes_moved = ( _ptr - 
string_value );
		copy ( _ptr, pattern_to_replace, 
number_of_bytes_moved, ( alocation_size - 1 ), 
				( strlen ( 
pattern_to_replace ) - strlen ( pattern_2b_replaced ) ) );
		_ptr += 1;
	}


	printf ( "\n string :%s, no of occurence :%d, 
size :%d", string_value, _count, alocation_size );

	free ( string_value );
}
 
0
Abdur Rab
 
 
Question
what is the output of below pgm?
void main()
{
 int i=0;
if(i)
printf("pass");
else
printf("fail");
}
Rank Answer Posted By  
 Question Submitted By :: Raji
I also faced this Question!!   © ALL Interview .com
Answer
fail
because here if is taking 0 boolean value means condition
becomes false and else will be executed
 
0
Himanshu Goel
 
 
Answer
fail
 
0
Sweta
 
 
Question
Is the C language is the portable language...If yes...Then 
Why...and if not then what is problem so it is not a 
Portable language..???
Rank Answer Posted By  
 Question Submitted By :: Chitransh
This Interview Question Asked @   TCS
I also faced this Question!!   © ALL Interview .com
Answer
C as a language is portable across any platforms, as it 
needs a compiler to compile in different platforms.

The drawback of compiled 'C' code is "Architecture 
Dependent" and hence the code compiled in 32 bit 
architecture cannot be used for 64 bit.
 
0
Abdur Rab
 
 
Question
what is use of for loop?
Rank Answer Posted By  
 Question Submitted By :: Kannan.p
This Interview Question Asked @   Wipro
I also faced this Question!!   © ALL Interview .com
Answer
for loop use is more then one calculation or process can be 
performed, for example:
          for(int i=0;i<5;i++)
          { 
                printf("%d",i);
           }
In the above example the printf statement can be excuted in 
five times.
 Output:0 1 2 3 4
 
0
Geetha
 
 
Answer
for loop use is one are more then printing in printup 
statements.
 
0
Kannan.p
 
 
Answer
for loop is used to repeate the process for certain number 
of time s known.
 
0
Murugasundari
 
 
Answer
for loop is executed as long as condition is true and 
process the loop until condition is fail.
 
4
Keshav.gadde
 
 
Answer
it is a loop which can have 3 conditions like
1)initiating a value to a variable
2)incrementation/decrementation
3)and a specific condition
 
0
Swathi
 
 
Answer
for the repeated eecution of a statement or a block we use 
for loop.
 
0
Gunasekhar
 
 
Answer
testing the condition more than one time.when it gets true 
the loop will be finished.
 
0
Madhu
 
 
Question
How to link calculator in oops concept? how is it working in
oops concept?
why dont  u using in beginning of program 'z' in abap(sap)?
Rank Answer Posted By  
 Question Submitted By :: Sarojajanakiram2007
I also faced this Question!!   © ALL Interview .com
Answer
looop concept
 
1
Iyyappan
 
 
Answer
calculator:
data
{numbers, arithmetic operators}
functions
{add(),sub(),multiply(),divide().....}
 
1
Bharghavi
[No]
 
 
Question
what do u mean by html
Rank Answer Posted By  
 Question Submitted By :: Trilochan1
I also faced this Question!!   © ALL Interview .com
Answer
hypertext markuplangauge.... it is webdesign
 
0
Iyyappan
 
 
 
Back to Questions Page
 
 
 
 
 
   
Copyright Policy  |  Terms of Service  |  Help  |  Site Map 1  |  Articles  |  Site Map  |   Site Map  |  Contact Us interview questions urls   External Links 
   
Copyright © 2007  ALLInterview.com.  All Rights Reserved.

ALLInterview.com   ::  Forum9.com   ::  KalAajKal.com