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 >> ERRORS >> C-C++-Errors
 
 


 

Back to Questions Page
 
Question
main()
{
  char c;
  for(c='A';c<='Z';c++)
getch();
}
Rank Answer Posted By  
 Question Submitted By :: Satrughna Sethi
I also faced this Question!!   © ALL Interview .com
Answer
NO ERRORS but result...........
 
4
Ravi
 
 
Answer
if ther s no body for the 'for' loop,it should end with 
semicolon..(i.e)
main()
{
  char c;
  for(c='A';c<='Z';c++);
getch();
}
or
main()
{
  char c;
  for(c='A';c<='Z';c++)
   {}
getch();
}
 
0
Bharghavi
 
 
Answer
in this question whenever the loop excuted getch() take 
input after that next loop is excuted and similar getch() 
take another input 
that think do untill the conditions of c<='z' is not 
completed
 
0
Rakesh
 
 
 
Answer
God help those who help themselves!
try it ur's self because i don't know about this programming
brother! i'm sorry forgive me.
 
0
Carlos
 
 
Answer
The initial condition is c='A'.
Here the the statement "getch();" is the body of the loop.
it is executed once and c becomes 'B' and again the loop is
executed.
This is done,I mean the loop is executed 26 times.
when c become 'Z' the loop is executed one more time(because
the condition is c<='Z')and then the program exit.
 
0
Sujeesh Krishnan
 
 
Answer
this wont show any errors since syntactically it is correct...
but since there is no instructions after for loop for operations unfortunelety getch() will be taken as the next instruction , and thus compiler system will be under ambiquity. since the character key pressed will be taken as the value of getch() so that will say to the OPERATING SYSTEM that compilation has got over and it will return to the IDE... but for loop has not got over.. so this depends on the compilers usage............



thank u
 
0
Vignesh1988i
 
 
Answer
No Errors
loop will execute for 26 times,each time it will wait for an
input and finally terminate when c becomes > Z.
 
0
Aaaaaaa
 
 
Question
how to convert decimal to binary in c using while loop 
without using array
Rank Answer Posted By  
 Question Submitted By :: Guest
I also faced this Question!!   © ALL Interview .com
Answer
Void main()
{
   int dec,i=1,rem,res=0;
   Printf("Enter the Value %d",&dec);
   while(dec!=0)
    {
        rem=dec%2;
        dec=dec/2;
        res=res+(i * 1);
        i=i*10;

    }
printf("The Binary value is %d",res);
}
 
1
Sudha
 
 
Answer
main()
{
    int dec,rem,ans=0;
    printf("Enter the number\n");
    scanf("%d",&dec);
    while(dec>=2)
    {
        rem=dec%2;
        dec=dec/2;
        if(rem==0)
            ans=ans*10;
        else
        ans=(ans*10)+1;
    }
    printf("The binary number is");
    while(ans>0)
    {
        rem=ans%10;
        ans=ans/10;
        printf("%d",rem);
    } 
    getch();
    return 0;
}
 
0
Sujeeshkrishnan
 
 
Answer
void main()
{
   int dec,rem,i=1;
   long int bin=0;
   printf("Enter the decimal number : ");
   scanf("%d",&dec);
   while(dec>0)
   {
      rem=dec%2;
      dec=dec/2;
      bin=bin+(i*rem);
      i=i*10;
   }
   printf("The binary number is %l",bin);
   getch();
}

Explanation:
The output variable bin is taken as long int bcoz it might 
exceed the range of normal int.

e.g.
dec=25

Then

bin=(1*1)+(10*0)+(100*0)+(1000*1)+(10000*1)
   =11001
 
0
Lakshya Mehra
 
 
Answer
#include<stdio.h>

int main()
{
int n, rem, num, i=1;

printf("enter no\n");
scanf("%d", &n);

while(n>0 )
 {
    rem = n % 2;
    n = n/2;
    num = (rem * i)+num;
    i = i  * 10;
 }
 
 printf("binary no: %d", num);
}
 
0
Sachin
 
 
Answer
@sudha
ur code is abs right with a minor mistake.
main()
{
int num,rem,b=0,i=1;
printf("enter num");
scanf("%d",&num);
while(num)
{
          rem=num%2;
          num=num/2;
          b=b+rem*i;
          i=i*10;
           }
           printf("\n%d",b);

}
 
0
@pravin.08
 
 
Answer
all these answers crap

when you
b = b+rem*i
b is filled with int number
and adds the next one to it in the loop 
so it wont be as  b= 10011001
it will be b= the number i have intered 
you idiots ....
 
0
Sam
 
 
Answer
/* convert a decimal number to binary */
	int dectobin(int dec)
	{
		int bin=0, i=1;
		while(dec!=0)
		{
			bin+=(dec%2)*i;
			dec=dec/2;
			i*=10;
		}
		return bin;
	}
 
0
Nick
 
 
Question
Find the error (2.5*2=5)
(a) X=y=z=0.5,2.0-5.75
(b) s=15;
Rank Answer Posted By  
 Question Submitted By :: Bakhshi
I also faced this Question!!   © ALL Interview .com
Answer
If a float variable multiply by an integer, it will give 
answer in float. So the answer should be in float.
 
0
Preeti
 
 
Answer
5.0
 
0
Ajay03002
 
 
Answer
(a) you can not do 
x=y=z=0.5 in c++ it will throw error..
undefine symbol y & z...
 
0
K.k
 
 
Question
UINT i,j;
i = j = 0;
i = ( i++ > ++j ) ? i++ : i--;

explain pls....
Rank Answer Posted By  
 Question Submitted By :: Boss
I also faced this Question!!   © ALL Interview .com
Answer
(i++ > j++) gives 0 because 0 > 0 is false so it return 0.
before returning 0 i is 1 ,but it is overwrite by 0.
 In the Conditional operator false means ,it executes i++;
so i is 1.
 
0
Chaneswara Reddy
 
 
Answer
1.we know that i=j=0 initially

2.then it will checks the non-incremented 'i' value(i.e 0) 
with incremented 'j' value(i.e 1). So obviously condition 
is falls.

3.now false statement has to be executed i.e (i--),before 
executing this 'i' value is (i.e incremented value)'1' 
after executing false condition(i.e i--)the value of 'i' 
becomes  '0'.

4.So the value of 'i' is '0'.
 
0
Raj
 
 
Answer
UNIT i,j :
this line indicates that UNIT is an user defined data type. it may been declared as follows :

          typedf int UNIT
we are making the code more readable

i=j=0 :  indicates that the var. i and j are declared as 0

i=(i++>++j) ? i++ : i-- : the process here is 

i++ is an post  incrementation . if this is compared with any relational or any operaters first that value will be operated first and the 'i' will get incremented ........
but ++j if we take first thing it will increment the value and then operation will be performed

so when it is compared first i will be 0 and j will be 1 so 0 is not greater than 1. so false, so it will go to the statement after  ':' so i-- is there so final value of i will be 0.

thank u
 
0
Vignesh1988i
 
 
Question
Given an  int variable  n that has been initialized to a
positive value and, in addition,  int variables  k and 
total that have already been declared, use a  do...while
loop to compute the sum of the cubes of the first  n whole
numbers, and store this value in  total . Thus if  n equals
4, your code should put 1*1*1 + 2*2*2 + 3*3*3 + 4*4*4 into 
total . Use no variables other than  n ,  k , and  total . 
Rank Answer Posted By  
 Question Submitted By :: Andrew Gargani
I also faced this Question!!   © ALL Interview .com
Answer
total=0;
k=1;
do
{
total=total+k*k*k;
k++;
}while(k<=n)
 
0
C.muruganandham
 
 
Answer
total=0;
while(n>=1)
{
  total+=n*n*n;
  n--;
}
 
0
Sachin
 
 
Answer
#include<stdio.h>
#include<conio.h>
#include<math.h>
main()
{
int n=3;
int k=1,total=0;
do
{
    total=total+(pow(k,3));
    k=k+1;
}
while(k<=n);
printf("%d",total);
getch();
return 0;
}
 
0
Sujeesh Krishnan
 
 
Question
Given an  int variable  n that has already been declared and
initialized to a positive value, and another  int variable 
j that has already been declared, use a  do...while loop to
print a single line consisting of  n asterisks. Thus if  n
contains 5, five asterisks will be printed. Use no variables
other than  n and  j . 
Rank Answer Posted By  
 Question Submitted By :: Andrew Gargani
I also faced this Question!!   © ALL Interview .com
Answer
//1st method..
there is no use of j.as explained below
int j,n=psitive value;
do
{
cout<<"*";
n--;
}while(n!=0);
//2nd we can use j..
int j=0;
do
{
cout<<"*";
j++;
}while(j!=n);
 
1
Mahfooz
 
 
Question
Given that two int variables, total and amount, have been
declared, write a loop that reads integers into amount and
adds all the non-negative values into total. The loop
terminates when a value less than 0 is read into amount.
Don't forget to initialize total to 0.
 

Instructor's notes: This problem requires either a while or
a do-while loop.
Rank Answer Posted By  
 Question Submitted By :: Andrew Gargani
I also faced this Question!!   © ALL Interview .com
Answer
total=0;
cin>>amount;
while (amount>=0)
{
total=total+amount;
cin>>amount;
}
 
0
Helen
 
 
Question
Given that two  int variables,  total and  amount , have
been declared, write a sequence of statements that: 
 initializes  total to 0
 reads three values into  amount , one at a time.

 After each value is read in to  amount , it is added to the
value in  total (that is,  total is incremented by the value
in  amount ). 


Instructor's notes: If  you use a loop, it must be a for loop.
And if you use a loop control variable for counting, you
must declare it.
Rank Answer Posted By  
 Question Submitted By :: Andrew Gargani
I also faced this Question!!   © ALL Interview .com
Answer
total= 0;

scanf("%d",&amount);
total +=amount;
scanf("%d",&amount);
total +=amount;
scanf("%d",&amount);
total +=amount;
 
0
Raj
 
 
Question
who was the present cheif governor of reserve bank of india
Rank Answer Posted By  
 Question Submitted By :: Akshay
This Interview Question Asked @   SBI
I also faced this Question!!   © ALL Interview .com
Answer
Mr.Subbarao
 
0
Cud_ramesh
 
 
Answer
duvvuri subba rao
 
0
Siva
 
 
Answer
The question itself is gramatically wrong.........
this is something of the sort "did you eat tomorrow?"
 
0
Madhu
 
 
Question
void main()
{
int i=1;
printf("%d%d%d",i,++i,i++);
}
Cau u say the output....?
Rank Answer Posted By  
 Question Submitted By :: Mariaalex007
I also faced this Question!!   © ALL Interview .com
Answer
3   3    1
 
5
Saurabh Mehra
 
 
Answer
its .....1 2 2
 
0
Ajay
[PSNCET]
 
 
Answer
2 2 1
 
2
Rajababu
[PSNCET]
 
 
Answer
113
 
0
Idds
[PSNCET]
 
 
Answer
1 2 3
 
0
Kanshi Ram
[PSNCET]
 
 
Answer
the output will be 3 3 1.
 
0
Vignesh1988i
[PSNCET]
 
 
Answer
sorry for not explaining it.

this is due to a concept of STACK which is a DATA STRUCTURE.

take the statement : printf("%d%d%d",i,++i,i++);

this list of variables will be getting stored in the stack. like the way shown:
        i++
        ++i
         i
since the operation of the stack is  LIFO(last in first out)
the process will be done as said as LIFO but while retriving the data it will be printing according to the printf statement so only the output   3 3 1
 
0
Vignesh1988i
[PSNCET]
 
 
Answer
331
 
0
Ravi
[PSNCET]
 
 
Answer
1 1 2
 
0
Ismail Ns
[PSNCET]
 
 
Answer
Yes, but before giving the answer I wanna discuss the question.
In printf() function compiler calculates the values from
right to left (i.e. at first calculates the vale of i++,
then ++i and at last i)but prints the values from left to right.
So compiler at first calculates the value of i++, here i=1
so the value is printed 1 for i++, in the post increment the
value of i becomes 2, but in the pre increment which is ++i,
the value becomes 3, so the value is printed 3 for ++i, now
the value of i is 3, for this reason the value is printed
again 3 for i. But as I said before printf() function prints
from left to right 
so the output will be 3 3 1
 
0
Arnob Kumar Pal
[PSNCET]
 
 
Question
void main()
{
for(int i=0;i<5;i++);
printf("%d",i);
}

What is the output?..
Rank Answer Posted By  
 Question Submitted By :: Mariaalex007
I also faced this Question!!   © ALL Interview .com
Answer
Answer is 5..........
 
0
Mariaalex007
 
 
Answer
declaring int i inside for loop is not available in
traditional 'c'
 
0
Kumaran
[PSNCET]
 
 
Answer
we can not declare loop condition variable in c..we can do
in c++.
 
0
Mahfooz
[PSNCET]
 
 
Answer
it goes from 0 to 5

 and  print i
 
0
Samir Isakoski
[PSNCET]
 
 
Answer
why shoul have a cout if is c++

 buth this is c  (printf)

  and why cannot daclare a int in the for ciclus
 
0
Samir Isakoski
[PSNCET]
 
 
Answer
We can't declare a variable in any part of the program
rather than the declaration part.
It doesn't matter whether you use a loop to print or not.
When the statements which are to be executed begins(Here the
looping statement)no declaration is possible in C.
You can do it in C++,C#,java etc.
 
0
Sujeesh Krishnan
[PSNCET]
 
 
Question
wap for bubble sort
Rank Answer Posted By  
 Question Submitted By :: Joshin
I also faced this Question!!   © ALL Interview .com
Answer
n=No of elements in an array;

for(i=0;i<n;i++)
{for(j=0;j<n-i;j++)
   {if(arr[j]>arr[j+1])
     swap(arr[j],arr[j+1]);
   }  
}

void swap(int*x, int*y)
{
  int temp;
   temp = *x;
   *x = *y;
   *y = temp;
}
 
0
Sachin
 
 
Answer
//n=No of elements in an array;
int n;
int []a;
for(i=0;i<n;i++)
{
 for(j=0;j<n-i;j++)
   {
    if(a[j]>a[j+1])
     {   //swap function for the variables in the array
       int temp=a[j];
        a[j]=a[j+1];
         a[j+1]=temp;
         }
    }
}
 
0
Mandeep M Gaba
 
 
Question
write a profram for selection sort

whats the error in it?
Rank Answer Posted By  
 Question Submitted By :: Joshin
I also faced this Question!!   © ALL Interview .com
Answer
//program for selection sort
#include<stdio.h>
#include<conio.h>
#define MX 100
void selection(int [], int);
void selection(int a[],int n)
{
	int minindx,t;
	int i,j;
	for(i=0;i<n-1;i++)
	{
		minindx=i;
		for(j=i+1;i<n;j++)
		{
			if(a[j]<a[minindx])
			minindx=j;
		}
		if(minindx!=i)
		{
		t=a[i];
		a[i]=a[minindx];
		a[minindx]=t;
		}
	}
}
void main()
{
	int a[MX],i,n;
	clrscr();
	printf("enter total num of elements:");
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
	scanf("%d",&a[i]);
	}
	selection(a,n);
	printf("sorted arrau:\n");
	for(i=0;i<n;i++)
	{
		printf("%d \t",a[i]);
	}
	getch();
}
 
0
Joshin
 
 
 
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