Series: Subject: Topic:

# C Interview Questions

Showing Questions 1 - 5 of 5 Questions
Sort by:
|

Write a program to implement the fibonacci series

Member Since Jun-2007 | Answered On : Jul 27th, 2007

```Code
#include
int main()
{
unsigned int i = 0, j = 0, sum = 1, num;
printf("nEnter the limit for the series ");
scanf("%d", &num);
while (sum < num) {
printf("%d ", sum);
i = j;
j = sum;
sum = i + j;
}
getch();
}
```

Answered by: n.m.sudesh kumar on: Mar 20th, 2013

```Code#include<stdio.h>
#include<conio.h>
void main()
{
int pre=0,next=1,sum=0,n;
clrscr();
printf("enter the value of n:");
scanf("%d",&n);
while(pre<=n)
{
printf("the fibonacci series; %d
",pre);
sum=pre+next;
pre=next;
next=sum;
}
getch();
}```

limit:5
01123

Sum of two numbers without using arithmetic operators

Ex:int a=10;int b=10;int sum=a+b;without using "+" operator calculate sum

Member Since May-2008 | Answered On : Jul 17th, 2008

void main()
{
int a=10,b=20;
while(b--) a++;
printf("Sum is :%d",a);
}

Answered by: And on: Aug 28th, 2012

For two positive numbers:

int main(){
int a = 10;
int b = 10;

printf("%d",a ^ b | ((a & b)<< 1));
return 0;
}

```Code#include<stdio.h>
#include<conio.h>
main()
{
int a=20,b=10,c;
clrscr();
c=a-~b-1;             //it will change the sign of operator truly magic
printf("sum is %d",c);
getch();
return 0;
}```

Sequence of function execution

Printf("%d%d",f1(),f2());what is the sequence of function execution of the above statement. 1. Printf, f1(), f2()2. Printf, f2(), f1()3. F1(), f2(), printf4. F2(), f1(), printf.

Member Since Oct-2009 | Answered On : Oct 30th, 2009

Let's understand this by going through the following code

#include<stdio.h>
int f1();
int f2();

void main()
{
printf("%dt%d",f1(),f2());
}

int f1()
{
printf("f1() enteredn");
return 4;
}

int f2()
{
printf("f2() enteredn");
return 5;
}

O/P-

f2() entered
f1() entered
4        5

we can conclude f2() is 1st executed
then f1() and in the end printf().hence we can say the precedence of execution of functions are from right to left.

Answered by: geek Jack on: Aug 2nd, 2010

printf();
then f2()
then f1()
then again printf()  to print the value in f1 f2
these are arguments to printf function.

Answered by: omkar.lenka on: Jul 29th, 2010

3)f1(),f2(),printf

What is a const pointer?

Answered On : Apr 27th, 2007

Constant pointer is NOT pointer to constant. Constant pointer means the pointer is constant. For eg:
Constant Pointer
int * const ptr2 indicates that  ptr2 is a pointer which is constant. This means that ptr2 cannot be made to point to another integer. However the integer pointed by ptr2 can be changed.

Where as a Pointer to constant is
const int * ptr1 indicates that ptr1 is a pointer that points to a constant integer. The integer is constant and cannot be changed. However, the pointer ptr1 can be made to point to some other integer.

Answered by: Jegan Chakkravarthy on: Jan 7th, 2011

An ordinary pointer variable preceeded with the "const" modifier. This prevents the value initialised from getting changed.

Answered by: anandkumarjha on: Aug 28th, 2010

Absolutely there is the vast difference between constant pointer and the pointer to a constant.it will be more clear with the examples of both the types.CONSTANT POINTER:-int const *a...this means the...

C if condition puzzle

What's the "condition" so that the following codesnippet prints both helloworld !If "condition"printf ("hello");elseprintf("world");

Member Since Jun-2008 | Answered On : Jun 6th, 2008

if ( ! ( printf("Hello ") ) )
printf("Hello");
else
printf("World");

Answered by: fazil.vp on: Apr 24th, 2009

/* Solution 1: */int main(int argc, char* argv[]){ if( argc == 2 || main( 2, NULL ) ) { printf("Hello "); } else { printf("Worldn"); } return 0;}/* Solution 2 (Only for Unix an...

Answered by: dutta_sudipta on: Sep 18th, 2008

Is it like this?

void main()
{
int a=2;
while(a--)
if(a)
printf("Hello ");
else
printf("World!");
}