December 2012

C Problems and Solutions

1. What is wrong in the following problem
#include
main() {
int i,j;
j = 10;
i = j++ - j++;
printf("%d %d", i,j);
}
Ans: 0, 12

2. What is the output of the following problem
#include
main() {
int j;
for(j=0;j<3;j++)
foo();
}
foo() {
static int i = 10;
i+=10;
printf("%d\n",i);
}

Ans: i is static variable, so output is

20
30
40

3. What is wrong in the following code

#include
#include

main()
{
char *c;
c = "Hello";
printf("%s\n", c);
}

Ans: Hello, The code is successfully running

4. What is the final value of i and how many times loop is executed ?

#include
main()

{
int i,j,k,l,lc=0;
/* the input is given as 1234 567 */
printf("Enter the number string:<1234 567 >\n");
scanf("%2d%d%1d",&i,&j,&k);
for(;k;k--,i++)
for(l=0;l printf("%d %d\n",i,l);}
printf("LOOPS= %d\n", lc-1);
}
Ans: i = 16, and loop is executed for 169 times

5. What is the output of the following program

#include
main() {
union {
int a;
int b;
int c;
} u,v;
u.a = 10;
u.b = 20;
printf("%d %d \n",u.a,u.b);
}

Ans : 20 20
Read More

C Problems and Solutions - 2

6. What is the output?

#include<stdio.h>
main(){
char a[]="hellow";
char *b="hellow";
char c[5]="hellow";
printf("%s %s %s ",a,b,c);
printf(" ",sizeof(a),sizeof(b),sizeof(c));
}

Ans: hellow,hellow,hellow
6,2,5

7. What is the output?

#include<stdio.h>
main()
{
float value=10.00;
printf("%g %0.2g %0.4g %f",value,value,value,value)
}

Ans : 10,10,10,10.000000

8. main()
{
funct(int n);
{
switch(n)
case1:
m=2;
break;
case2:
m=5;
break;
case3:
m=7;
break;
default:
m=0;
}

Ans : output is m=0

9. #include<stdio.h>
void function1;
int i-value=100;
main()
{
i-value=50;
function1;
printf("i-value in the function=",i-value);
printf("i-value after the function=",i-value);
}
printf("i-value at the end of main=",i-value);
functioni()
i-value=25;

Ans: i-value in the function=25;
i-value after the function=50;
i-value at the end of the main=100;

10. what is output of the following program
main()
{
int i=3;
while(i--)
{
int i=100
i--;
printf("%d..",i);
}
}

Ans: 99..99..99..99

IT / Computer - Acronyms and Abbreviations

1. ODBC means open data base connectivity

2. ASCII stands for american standard for information interchange

3. FLOPS stands for floating point operation per second

4. RAID stands for redundant array of independent disks or redundant array of inexpensive disks