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                      
info       Did you received any Funny E-Mails from your Friends and like to share with rest of our friends? Yeah!! you can post that stuff   HERE
Google
 
Categories >> Software >> Programming-Languages >> C
 
 


 

Back to Questions Page
 
Question
HOW TO SWAP TWO NOS IN ONE STEP?
Rank Answer Posted By  
 Question Submitted By :: Tuhinkantibhandari
This Interview Question Asked @   Satyam
I also faced this Question!!   © ALL Interview .com
Answer
#include<stdio.h> 	
main()
{
 int a=5,b=9;
 printf("%d %d \n",a,b);
 a^=b^=a^=b;
 printf("%d %d \n",a,b);
}
 
0
Vijay
 
 
Answer
main()
{
int a,b,c;
printf("enter two no's :");
scanf("%d%d",&a,&b);
c=a^=b^=a^=b;
printf("%d",c);
}
 
0
Sasikumar
[Calcutta University]
 
 
Answer
void main()
{
 int a,b;
 printf("Enter two numbers\n");
  scanf("%d%d",&a,&b);
 b=a+b-(a=b);
 printf("%d %d ",a,b);
}
 
0
Shiva Kumar
[Calcutta University]
 
 
 
Answer
amaresh@Hare-Krishna:~$ cat swp.c 
#include<stdio.h>
int
main(){
        int a=5,b=6; // Compile using gcc -Wall
#ifdef DEBUG // to avoid compiler warnings
        a ^=b^=a^=b;
#endif
        printf("value of a is %d and b is %d\n",a,b);
        return 0;
}
 
0
Amaresh Chandra Das
[Calcutta University]
 
 
Answer
step 1.
a=b,b=a
 
0
Sasa
[Calcutta University]
 
 
Answer
#define SWAP(x,y) int t;t=x;x=y;y=t;
 
0
Ashik
[Calcutta University]
 
 
Answer
#define swap(a,b) a^=b^=a^=b;
 
0
Ashik
[Calcutta University]
 
 
Answer
#include(stdio.h);
#include(stdlib.h);
void main()
{
int a=10,b=20;
swap(a,b);
a=b&b=a;
printf("%d%d",a,b);
}
 
0
N.ramesh
[Calcutta University]
 
 
Answer
(a=a-(b=(a=a+b)-b));
 
0
Rajkumar
[Calcutta University]
 
 
Answer
int a=5,b=2;
printf("%d %d");


execute the pgm deftly swap wil tak place.......
 
0
Priya
[Calcutta University]
 
 
Answer
#include<stdio.h>
#include<conio.h>
void main()
{
int a=5,b=2,t;
clrscr();
printf("a=%d,b=%d",a,b,b=t,a=b,t=a);
getch();
}
 
0
Venkatesh Sabinkar
[Calcutta University]
 
 
Answer
#include<stdio.h>
#include<conio.h>
void main()
{
int a=5,b=2,t;
clrscr();
printf("a=%d,b=%d",a,b,b=t,a=b,t=a);
getch();
}
 
0
Venkatesh Sabinkar
[Calcutta University]
 
 
Question
how to find sum of digits in C?
Rank Answer Posted By  
 Question Submitted By :: Shrth
This Interview Question Asked @   CTS
I also faced this Question!!   © ALL Interview .com
Answer
example:435
the answer is 4+3+5=12
 
0
Shrth
 
 
Answer
void main()
{
int a[20];
printf("enter no of values");
scanf("%d",&n);
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
for(i=0;i<n;i++)
{
sum=sum+a[i];
}
printf("%d",sum);
}
 
0
Leelanarasimhareddy
 
 
Answer
main()
{
int n,i,sum=0,r;
printf("enter the value");
scanf("%d",&n);
for(i=0;i<=5;i++)
{
r=n%10;
n=n/10;
sum=sum+r;
}
 
0
Leninraj
 
 
Answer
#include<stdio.h>
#include<conio.h>

void main()
{
  int x,y;
  clrscr();
  
  printf("\nEnter the value of any two numbers to be    
added\n");
  scanf("%d%d",&x,&y);

  x=x+y;
  printf("%d",x);
  getch();
}
 
0
Neha Khurana
 
 
Answer
main()
{
int n,i,sum=0,r;
printf("enter the value");
scanf("%d",&n);
while(n!=0)
{
r=n%10;
n=n/10;
sum=sum+r;
}
 
0
Bhagwat
 
 
Answer
main()
{
int n,i,sum=0,r;
printf("enter the value");
scanf("%d",&n);
while(n)
{
rem=num%10;
sum=sum+rem;
num=num/10;
}
printf("sum = %d",sum);
}
 
0
Pankaj Khaitan
 
 
Answer
main()
{
int n,i,sum=0,r;
printf("enter the value");
scanf("%d",&n);
while(n!=0)
{
r=n%10;
n=n/10;
sum=sum+r;
}
printf("\nsum of digits is %d",sum);
}
 
0
Pooja
 
 
Answer
try this....

#include<stdio.h>
int main()
{
int n,m,sum=0;
scanf("%d",&n);
for(m=0;((m=n%10)!=0);n=(n/10))
sum+=m;
printf("count is %d\n",sum);
}
 
0
Gg
 
 
Answer
#include<stdio.h>
#include<conio.h>
int main()
{
int n,m,d,m1,s=0,s1;
printf("enter the number ");
scanf("%d",&n);
m=n%10;
d=n/10;
while(d>=10)
{
m1=d%10;
d=d/10;
s=s+m1;
}
s1=s+m+d;
printf("\nThe sum of digits is ");
printf("%d",s1);
getch();
}
 
0
Ruchi
 
 
Answer
#include <stdio.h>
#include <conio.h>

void main()
{
   int sum=0, num, mul=1;
   printf("Enter the number");
   scanf("%d", &num);
   
   while(num)
   {
    sum = sum + ((num%10)*mul);
    num = num/10;
    mul = mul * 10;
   }
   
   printf("Sum is %d", sum);
}
 
0
Giri
 
 
Question
what is the return value (status code) of exit() function....
what the  arguments(integer  value) passed  to it means....
Rank Answer Posted By  
 Question Submitted By :: Vitrathinam
This Interview Question Asked @   TCS
I also faced this Question!!   © ALL Interview .com
Answer
0 if successful and a non-zero value if unsuccessful.
        The argument signifies whether the program have
executed successfully or not.
   If 0,then it is successful.And a non-zero value indicates
an error.Several type of errors may occur.So a non-zero
value is supplied.Not 1 or 2 or...some specific value.
 
0
Arindam Majumder
 
 
Question
can anyone please tell me wat is backlogs... i was looking 
for the job openings where i read this.. eligibility 
criteria minimum 70% in degree without backlogs. is that 
arrear.. if so is it standing arrear or history of 
arrears... please help me...
Rank Answer Posted By  
 Question Submitted By :: Flethitia
I also faced this Question!!   © ALL Interview .com
Answer
Backlogs means standing arrears
 
0
Jainu
 
 
Answer
backlog means passing subjects in first attempt. Without any
subjects pending
 
0
Tushar
 
 
Answer
even i cant understand this standing arrear part ... there 
should be no fail in any subject in
 
0
7i6 Kioyu8
 
 
Answer
standing arrear mean therer shd b nofail in subjects of 
graduation or evn in class 10 or twelve ?
 
0
Weferg
 
 
Question
What is external and internal variables
What is dynamic memory allocation
what is storage classes in C
Rank Answer Posted By  
 Question Submitted By :: Ang
I also faced this Question!!   © ALL Interview .com
Answer
Dynamic allocation is a pretty unique feature to C (amongst
high level languages). It enables us to create data types
and structures of any size and length to suit our programs
need within the program. 

storage classes

auto 
register 
static 
extern 
typedef
 
0
Rekha
 
 
Answer
External variable -- Variable that one going to be access
from another source file.Have life cycle for complete project.

Internal variable -- variable that one have the life cycle
for the particular  block.

Dynamic memory allocation --Allocation of memory during RUN
time.

Storage Class -- 

Automatic : by default 
Register : Use to access registers of CPU.If register is not
free than work as automatic.
Static : Have life cycle for whole project but access only
with in the initialized function block.Once initialized.
extern : above
 
0
Ravi Saini
 
 
Question
Explain following declaration
int *P(void); 
and
int (*p)(char *a);
Rank Answer Posted By  
 Question Submitted By :: Anil Rai
I also faced this Question!!   © ALL Interview .com
Answer
int *p(void) - says this is function with null parameter 
and returns a pointer to an integer.

int (*p)(char *a) - says this is function with a pointer to 
a char a as  parameter and returns a pointer to an integer.
 
0
Tibu
 
 
Answer
int* p(void) means p is a function that takes no argument a
return a pointer to integer.
int (*p)(char*a) means that p is a pointer to function that
take character pointer as argument and return an integer.
 
0
Vijay
 
 
Question
logic for generating all the combinations of the any number
of given letters.
ex:::::::::
if a,b,c,d are given the o/p should be
abcd,dcba,dbac,bcad,................
4*3*2*1 combinations............
Rank Answer Posted By  
 Question Submitted By :: Shiva034
This Interview Question Asked @   Infosys
I also faced this Question!!   © ALL Interview .com
Answer
#include <stdio.h>

void permute ( char* strptr, int start, int length )
{
	int count1;
	int count2;
	int temp;

	for ( count1 = start; count1 < length - 1; 
++count1 ) {
		for ( count2 = count1 + 1; count2 < length; 
++count2 ) {
			temp = strptr [ count1 ]; strptr [ 
count1 ] = strptr [ count2 ]; strptr [ count2 ] = temp;
			permute ( strptr, count1 + 1, 
length );
			temp = strptr [ count1 ]; strptr [ 
count1 ] = strptr [ count2 ]; strptr [ count2 ] = temp;
		}
	}
	printf ( "\n%s", strptr );
}

int main ( int argc, char* argv [] )
{
	char str[] = "abcd";

	permute ( str, 0, ( strlen ( str ) ) );

	return 0;	
}
 
0
Abdur Rab
 
 
Answer
#include<stdio.h>
#include<conio.h>
#include<string.h>

char a[10];
int m;

void permute(int n,int i)
{
int j;
for(j=i;j<m;j++)
{
printf("%c",a[j]);

if(n!=0)
  {
   permute(n-1,i+1);
  }
else
  {
   printf("%c\n",a[j]);
  }

}

void main()
{
  printf("enter the string to be permuted");
  scanf("%s",a);
  m=strlen(a);
  permute(m,0);
}
 
0
Ashok Kannan
 
 
Question
code snippet for creating a pyramids triangle
ex

     1
   2   2
 3   3   3
Rank Answer Posted By  
 Question Submitted By :: Shiva034
I also faced this Question!!   © ALL Interview .com
Answer
void main()  

 { 
 int n,i,j;
 printf("enter the num of rows\t:");
 scanf("%d",&n);
 
 for(i=1;i<=n;i++)
 {
	 for(int k=0;k<n-i;k++)
	 printf(" ");  
	 for(j=1;j<=i;j++)
		 printf("%d ",i);
	 printf("\n");
 }
}
 
0
Rajesh Kamar S
 
 
Answer
A SMALL IMPLEMENTATION OF POINTERS
 
#include<stdio.h>
#include<conio.h>
void main()
{
int n,*p,*q;
printf("enter the number of lines :");
scanf("%d",&n);
for(int i=1,p=&i;*p<=n;*p++)
{
printf("\n");
  for(int j=1,q=&j;*q<=*p;*q++)
{
printf("%d",*p);
printf(" ");
}
}
getch();
}
 
0
Vignesh1988i
 
 
Answer
main()
{
    int i,j,n;
    printf("enter the limit");
    scanf("%d",&n);
    for(i=1;i<=n;i++)
    {
         
        for(j=0;j<i;j++)
        {
            printf("%d",i);
        }
        printf("\n");
    }

}
 
0
Manvi
 
 
Question
How can I prevent other programmers from violating
encapsulation by seeing the private parts of my class?
Rank Answer Posted By  
 Question Submitted By :: Abalonesoft
I also faced this Question!!   © ALL Interview .com
Answer
Not worth the effort — encapsulation is for code, not people. 

It doesn't violate encapsulation for a programmer to see the
private and/or protected parts of your class, so long as
they don't write code that somehow depends on what they saw.
In other words, encapsulation doesn't prevent people from
knowing about the inside of a class; it prevents the code
they write from becoming dependent on the insides of the
class. Your company doesn't have to pay a "maintenance cost"
to maintain the gray matter between your ears; but it does
have to pay a maintenance cost to maintain the code that
comes out of your finger tips. What you know as a person
doesn't increase maintenance cost, provided the code you
write depends on the interface rather than the implementation. 

Besides, this is rarely if ever a problem. I don't know any
programmers who have intentionally tried to access the
private parts of a class. "My recommendation in such cases
would be to change the programmer, not the code" [James
Kanze; used with permission]. 

 
0
Abalonesoft
 
 
Question
How does C++ help with the tradeoff of safety vs. usability?
Rank Answer Posted By  
 Question Submitted By :: Abalonesoft
I also faced this Question!!   © ALL Interview .com
Answer
In C, encapsulation was accomplished by making things static
in a compilation unit or module. This prevented another
module from accessing the static stuff. (By the way, static
data at file-scope is now deprecated in C++: don't do that.) 

Unfortunately this approach doesn't support multiple
instances of the data, since there is no direct support for
making multiple instances of a module's static data. If
multiple instances were needed in C, programmers typically
used a struct. But unfortunately C structs don't support
encapsulation. This exacerbates the tradeoff between safety
(information hiding) and usability (multiple instances). 

In C++, you can have both multiple instances and
encapsulation via a class. The public part of a class
contains the class's interface, which normally consists of
the class's public member functions and its friend
functions. The private and/or protected parts of a class
contain the class's implementation, which is typically where
the data lives. 

The end result is like an "encapsulated struct." This
reduces the tradeoff between safety (information hiding) and
usability (multiple instances). 
 
0
Abalonesoft
 
 
Question
What is encapsulation?
Rank Answer Posted By  
 Question Submitted By :: Abalonesoft
I also faced this Question!!   © ALL Interview .com
Answer
Preventing unauthorized access to some piece of information
or functionality. 

The key money-saving insight is to separate the volatile
part of some chunk of software from the stable part.
Encapsulation puts a firewall around the chunk, which
prevents other chunks from accessing the volatile parts;
other chunks can only access the stable parts. This prevents
the other chunks from breaking if (when!) the volatile parts
are changed. In context of OO software, a "chunk" is
normally a class or a tight group of classes. 

The "volatile parts" are the implementation details. If the
chunk is a single class, the volatile part is normally
encapsulated using the private and/or protected keywords. If
the chunk is a tight group of classes, encapsulation can be
used to deny access to entire classes in that group.
Inheritance can also be used as a form of encapsulation. 

The "stable parts" are the interfaces. A good interface
provides a simplified view in the vocabulary of a user, and
is designed from the outside-in (here a "user" means another
developer, not the end-user who buys the completed
application). If the chunk is a single class, the interface
is simply the class's public member functions and friend
functions. If the chunk is a tight group of classes, the
interface can include several of the classes in the chunk. 

Designing a clean interface and separating that interface
from its implementation merely allows users to use the
interface. But encapsulating (putting "in a capsule") the
implementation forces users to use the interface.
 
0
Abalonesoft
 
 
Question
When is an interface "good"?
Rank Answer Posted By  
 Question Submitted By :: Abalonesoft
I also faced this Question!!   © ALL Interview .com
Answer
When it provides a simplified view of a chunk of software,
and it is expressed in the vocabulary of a user (where a
"chunk" is normally a class or a tight group of classes, and
a "user" is another developer rather than the ultimate
customer). 

The "simplified view" means unnecessary details are
intentionally hidden. This reduces the user's defect-rate. 
The "vocabulary of users" means users don't need to learn a
new set of words and concepts. This reduces the user's
learning curve.
 
0
Abalonesoft
 
 
Question
What is an object?
Rank Answer Posted By  
 Question Submitted By :: Abalonesoft
I also faced this Question!!   © ALL Interview .com
Answer
A region of storage with associated semantics. 

After the declaration int i; we say that "i is an object of
type int." In OO/C++, "object" usually means "an instance of
a class." Thus a class defines the behavior of possibly many
objects (instances).
 
0
Abalonesoft
 
 
Answer
An object is the instance of the class.. 

it is the only gateway to access the entities defined in 
the class..
 
0
Shruti
[Abalonesoft Technologies]
 
 
Answer
Basic run time entity
 
0
Rajesh
[Abalonesoft Technologies]
 
 
 
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