CoolInterview.com - World's Largest Collection of Interview Questions & Answers, FAQs, queries, sample papers, exam papers, dumps, what, why, how, where, when questions
Our Services
Get 9,000 Interview Questions & Answers in an eBook.




Get it now !!
Send your Resume to 6000 Companies
Branches & Loops in C Interview Questions & Answers - Learning Mode
COOLINTERVIEW.COM C INTERVIEW QUESTIONS BRANCHES & LOOPS IN C INTERVIEW QUESTIONS QUESTIONS & ANSWERS - LEARNING MODE

Branches & Loops in C Interview Questions & Answers - Learning Mode

C provides two styles of flow control: Branching and Looping. Branching is deciding what actions to take and looping is deciding how many times to take a certain action. Branching is so called because the program chooses to follow one branch or another. Examples are if statement, ? : Operator, switch statement, break etc. Loops provide a way to repeat commands and control how many times they are repeated. C provides a number of looping way. Examples are while loop, for loop, do...while loop, break and continue statements etc.

Try Branches & Loops in C Interview Questions & Answers - Exam Mode

1 2 Next

Sort By : Latest First | Oldest First | By Rating

Branches & Loops in C Interview Questions & Answers - Learning Mode
Try Branches & Loops in C Interview Questions & Answers - Exam Mode
Question: if "condition"
printf("Hello");
else
printf("World")

what should be the condition,
so the output will be HelloWorld.


Answer: if(!printf("hello"))
printf("hello");
else
printf("world"); Source: CoolInterview.com
Question: why n++ executes faster than n+1?




Answer: The expression n++ requires a single machine instruction such as INR to carry out the increment operation whereas, n+1 requires more instructions to carry out this operation. Source: CoolInterview.com
Question: Is NULL always defined as 0?

Answer: NULL is defined as either 0 or (void*)0. These values are almost identical; either a literal zero or a void pointer is converted automatically to any kind of pointer, as necessary, whenever a pointer is needed (although the compiler can?t always tell when a pointer is needed). Source: CoolInterview.com
Question: Can include files be nested?

Answer: Yes. Include files can be nested any number of times. As long as you use precautionary measures , you can avoid including the same file twice. In the past, nesting header files was seen as bad programming practice, because it complicates the dependency tracking function of the MAKE program and thus slows down compilation. Many of today?s popular compilers make up for this difficulty by implementing a concept called precompiled headers, in which all headers and associated dependencies are stored Source: CoolInterview.com
Question: How to print 1 to 100 without using any conditional loop?

Answer: By using recursive function. Source: CoolInterview.com
Question: Give some explanation for "for" LOOP ON C LANGUAGE?

Answer: The general format of for loop is:

for(Starting index;condition;incrementation)
{
//Body of the loop.
}

for example:
for(i=1;i<5;i++)
{
printf("%d",i);
}
In this example first the value of i is initialized to 1.Then it checks whether i<5.since the value of i is less than 5 it printf the value of i as 1 and then increments the i value by 1.The i value becomes 2 and again checks the condition and executes the printf statement until the condition become Source: CoolInterview.com
Question: C Program to print the following series:
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5


Answer: #include<stdio.h>
#include<conio.h>
void main()
{
int i,j;
clrscr();
for(i=0;i<=4;i++)
{
for(j=0;j<=i;j++)
{
printf("%d ",j+1);
}
printf("
");
}
getch();
} Source: CoolInterview.com
Question: void main()
{
int x=20,y=35;
x= y++ + x++;
y= ++y + ++x;
printf("
%d %d" , x,y);
}
/* please tell me the value of x and y at each and every moment. i dont need the answer but the explanation of the anamolus behavior of increment expression.*/


Answer: the answar x=57 & y=94
from first equqtion
x=y++ +x++
x=35+20=55
then X++=56
&y=36

now from second equation
y=++y + ++x
x now 57 & y=37
y=57+37=94
which is desire output Source: CoolInterview.com
Question: Nesting of loops in C may continue upto how many levels?


Answer: we can do nesting of loops in c upto 15 times. Source: CoolInterview.com
Question: How can we find out prime numbers from 1 to 50?

Answer: #include<stdio.h>
#include<conio.h>
void main()
{
int i,j,c,n;
clrscr();
for(i=2;i<50;i++)
{
c=0;
for(j=2;j<i;j++)
{
if(i%j==0)
c++;
}
if(c==0)
printf("%d
",i);
}
getch();
} Source: CoolInterview.com
Question: fibbonaci series program



Answer: #include <iostream>

using namespace std;
int main ()
{
int fOne = 1;
int fTwo = 1;
int fThree = 2;
long fN;
long fNN;

cout << "How many n terms do you want in the sequence: ";
cin >> fN;

for ( fN = 1 ; fN >= 3 ; fN++ )
{
for (fNN = 1; fNN >= fN; fNN++)
fNN = (fN - 1) + (fN - 2);
cout << fN;
Source: CoolInterview.com
Question: Write a pro gramme to show bubble sort on a set of 10 numbers?

Answer: #include<stido.h>
#include<conio.h>
main()
{
int a[10],i;
printf("Enter n");
scanf("%d",&n);
for(i=0;i<n;i++)
scanf("%d",&a[i]);
buuble_sort(a,n);
for(i=0;i<n;i++)
printf("%4d",a[i]);
}
void buuble_sort(int a[],int n)
{
int i,j, temp;
for(i=1;i<=n-1;i++)
for(j=0;j<n-i;j++)
{
if(a[j]>a[j+1])
{
Source: CoolInterview.com
Question: What is the output of the following program:

int main()
{
char buff[]={ 0x11,0x11,0x11,0x11,0x22,0x22,0x22,0x22,0x33,0x33,0x33,0x33};
char* pEnd = buff + sizeof(buff) -1;
long * plong = buff;
short* pshort = buff;

for(; plong<pEnd; plong++)
printf("0x%X
", plong);

for(; pshort<pEnd; pshort++)
printf("0x%X
", pshort);

return 0;
}


Answer: No answer available currently.
Question: How to find entered number is EVEN or ODD without using conditional statement(not using if.. else,if.. , else if..,while, do... while...., for....)



Answer: We can find a number is odd or even by a simple programmain(){int a[2],i;a[0]=0; //0--means Even Numbera[1]=1; //1--means Odd numberscanf("%d",&i);printf("%d",a[i%2]);getch();} Source: CoolInterview.com
Question: main()
{
float me = 1.1;
double you = 1.1;
if(me==you)
printf("I love U");
else
printf("I hate U");
}




Answer: Ans is i hate u because the of float and doubles are different. if condition is false.

Source: CoolInterview.com
Question: x) main()
{
printf("%x",-1<<4);
}




Answer: Depending on the machine implementation it will result in FFFFFF0 (for 32bit ) or FFF0 (16 bit ) Source: CoolInterview.com
Question: Which expression always return true? Which always return false?

Answer: expression if (a=0) always return false

expression if (a=1) always return true Source: CoolInterview.com
Question: /*Are my STATEMENTS in the following program correct
EXCEPT IN CASE 3 THE ARE WRONG SO PLEASE CORRECT IT*/
#include<stdio.h>
#include<conio.h>
#include<alloc.h>

void main()
{
int i=3;
int j;
clrscr();

//case 1:
//when only post increment in the expr then all 'i' get initial value
j = (i + i++);
printf("
POST");
printf("
i=%d j=%d", i ,j);

i=3;j=0;
j = (i++ + i++ + i);
printf("
i=%d j=%d", i ,j);


//case2:
//when only pre increment in the expr then all 'i' get final value
i=3;j=0;
j = (++i + i);
printf("
PRE");
printf("
i=%d j=%d", i ,j);


i=3;j=0;
j = (++i + ++i + i + ++i + ++i);
printf("
i=%d j=%d", i ,j);


//case 3:
/*when both pre and post increment in the expr then
A] i++ will get initial 'i' value and
B] ++i will get last incremented value
C] i in the increment expression takes the last second incremented
value means if final ++i/i++ gives value 5 then simply 'i' will
posses value 4 irrespective of the positon of i in the increment exp*/
printf("
POST AND PRE");
i=3;j=0;
j = ( i++ + i + ++i + ++i +i + i + i++);
printf("
i=%d j=%d", i ,j);

i=3;j=0;
j = (i++ + ++i + i);
printf("
i=%d j=%d", i ,j);
getch();
}


Answer: Just remember the simple logic:
Pre-increment takes place before statement is executed.
Post increment takes place after the statement is executed,
Answer to your question;
i=3, j=0;
j=i++ + i + ++i + ++i +i + i + i++
j=3++ + 3 + ++3.....
so value of i changes to 4
j=4++ + 4 + 4 + ++4
again
j=5++ + 5 + 5 + 5 + 5 + 5 + 5++
j=35
and i has bee post incremented twice so
i=7
easy ain't it!!!!!!!!!!!!
Source: CoolInterview.com
Question: write a C program for to aggregate a 8*8 matrix to 4*4 matrix using formula b11=(a11+a12+a21+a22)?

Answer: suppose u have matrix a[8][8].

int b[4][4],i,j;

for(i=0;(i<4);i++) {
for(j = 0,j<4;j++) {
b[i][j] = a[2*i][2*j]+a[2*i][2*j+1]+a[2*i+1][2*j]+a[2*i+1][2*j+1];
}
} Source: CoolInterview.com
Question: What is the output of the following program:

int main()
{
char buff[]={ 0x11,0x11,0x11,0x11,0x22,0x22,0x22,0x22,0x33,0x33,0x33,0x33};
char* pEnd = buff + sizeof(buff) -1;
long * plong = buff;
short* pshort = buff;

for(; plong<pEnd; plong++)
printf("0x%X
", plong);

for(; pshort<pEnd; pshort++)
printf("0x%X
", pshort);

return 0;
}


Answer: output:0xFFE80XFFEC0XFFF00XFFE80XFFEA0XFFEC0XFFEE0XFFF00FFF2 Source: CoolInterview.com

1 2 Next



India News Network
Latest 20 Questions
Payment of time- barred debt is: (a) Valid (b) Void (c) Illegal (d) Voidable
Consideration is defined in the Indian Contract Act,1872 in: (a) Section 2(f) (b) Section 2(e) (c) Section 2(g) (d) Section 2(d)
Which of the following is not an exception to the rule, "No consideration, No contract": (a) Natural love and affection (b) Compensation for involuntary services (c) Completed gift (d) Agency
Consideration must move at the desire of: (a) The promisor (b) The promisee (c) The promisor or any other party (d) Both the promisor and the promisee
An offer which is open for acceptance over a period of time is: (a) Cross Offer (b) Counter Offer (c) Standing Offer (d) Implied Offer
Specific offer can be communicated to__________ (a) All the parties of contract (b) General public in universe (c) Specific person (d) None of the above
_________ amounts to rejection of the original offer. (a) Cross offer (b) Special offer (c) Standing offer (d) Counter offer
A advertises to sell his old car by advertising in a newspaper. This offer is caleed: (a) General Offer (b) Special Offer (c) Continuing Offer (d) None of the above
In case a counter offer is made, the original offer stands: (a) Rejected (b) Accepted automatically (c) Accepted subject to certain modifications and variations (d) None of the above
In case of unenforceable contract having some technical defect, parties (a) Can sue upon it (b) Cannot sue upon it (c) Should consider it to be illegal (d) None of the above
If entire specified goods is perished before entering into contract of sale, the contract is (a) Valid (b) Void (c) Voidable (d) Cancelled
______________ contracts are also caled contracts with executed consideration. (a) Unilateral (b) Completed (c) Bilateral (d) Executory
A offers B to supply books @ Rs 100 each but B accepts the same with condition of 10% discount. This is a case of (a) Counter Offer (b) Cross Offer (c) Specific Offer (d) General Offer
_____________ is a game of chance. (a) Conditional Contract (b) Contingent Contract (c) Wagering Contract (d) Quasi Contract
There is no binding contract in case of _______ as one's offer cannot be constructed as acceptance (a) Cross Offer (b) Standing Offer (c) Counter Offer (d) Special Offer
An offer is made with an intention to have negotiation from other party. This type of offer is: (a) Invitation to offer (b) Valid offer (c) Voidable (d) None of the above
When an offer is made to the world at large, it is ____________ offer. (a) Counter (b) Special (c) General (d) None of the above
Implied contract even if not in writing or express words is perfectly _______________ if all the conditions are satisfied:- (a) Void (b) Voidable (c) Valid (d) Illegal
A specific offer can be accepted by ___________. (a) Any person (b) Any friend to offeror (c) The person to whom it is made (d) Any friend of offeree
An agreement toput a fire on a person's car is a ______: (a) Legal (b) Voidable (c) Valid (d) Illegal
Cache = 0.015625 Seconds