Results

Job Portal

Carresma jobs

Wednesday, July 25, 2012

if(printf("Logical Programs")); C Inteview Questions Get logical c programs with clear explanation.


Introduction:


Why programs ?

Programming is nothing but making the computers think the same way a human thinks. Programs are made for obtaining a specific solution which can even be solved by humans which when solved by us may consume time. So one thing is clear that man can do all things that a computer can do where in turn a computer can not do all things that a man can do.  Even though the computers are fast,reliable,and robust they are simply current consuming machines unless they are programmed. 

Predict the output

int main()
{
int x=0;
if(x==printf(""))
printf("selva");
else
printf("Neo");
return 0;
}

Coding to create a pyramid using numbers in c program


#include<stdio.h>
void main()
{
 int n;
 do
 {
  printf("How many lines you want to printn");
  scanf("%d",&n);
 }
  while((n<1)||(n>9));
  for(int i=1;i<=n;i++)
  {

   for(int j=1;j<=(n-i);j++)
   printf(" ");

   for(j=1;j<=i;j++)
                        printf("%d",j);    

                        for(j=(i-1);j>=1;j--)
   printf("%d",j);

   printf("n");

  }
}

Predict the output for this program


int main( )
{
printf("%d",printf("%d %d",5,5)&printf("%d %d",7,7));
return 0;
}

1 7 7 5 5
7 7 5 5 1
5 5 7 7 3
7 7 5 5 3

What is the output of the following program?


int main( )
{
printf(" %d %d",printf("%d %d",7,7),printf("%d %d",5,5));
return 0;
}


7 7 5 5 3 3
5 5 7 7 3 3
3 3 7 7 5 5
3 3 5 5 7 7



Produce 2 power n series using bitwise operator

I am printing 2n series up to 210

int main()
{
int i;
for(i=0;i<10;i++)
printf("%d\n",1<<i);

return 0; 
}

This will be the output of the above code

1
2
4
8
16
32
64
128
256
512

Extern variable :predict the output


int i=2;
int main()
{
extern int i;
clrscr();
printf("%d",i);
getch();
return 0;
}
int i=3;

predict the output

#include
void main(){
int check=2;
switch(check){
case 1: printf("D.W.Steyn");
case 2: printf(" M.G.Johnson");
case 3: printf(" Mohammad Asif");
default: printf(" M.Muralidaran");
}
}

(A) M.G.Johnson
(B) M.Muralidaran
(C) M.G.Johnson Mohammad Asif M.Muralidaran
(D) Compilation error
(E) None of the above

output - (c)

#include
#define a 10
main()
{
#define a 50
printf("%d",a);
}

Answer:
50
Explanation:
The preprocessor directives can be redefined anywhere in the program. So the most recently
assigned value will be taken.



main()
{
char *p;
p="Hello";
printf("%c\n",*&*p);
}
Answer:
H
Explanation:
* is a dereference operator & is a reference operator. They can be applied any number of
times provided it is meaningful. Here p points to the first character in the string "Hello". *p
dereferences it and so its value is H. Again & references it to an address and * dereferences
it to the value H.



main()
{
int i=-1;
+i;
printf("i = %d, +i = %d \n",i,+i);
}
Answer:
i = -1, +i = -1

Explanation:
Unary + is the only dummy operator in C. Where-ever it comes you can just ignore it just
because it has no effect in the expressions (hence the name dummy operator).


Posted by sharmi

static

main()
{
static int var = 5;
printf("%d ",var--);
if(var)
main();
}
Answer:
5 4 3 2 1
Explanation:
When static storage class is given, it is initialized once. The change in the value of a static
variable is retained even between the function calls. Main is also treated like any other ordinary function,
which can be called recursively.

Posted by sharmi

Short circuit operators

Short circuit operator is operator in which first operand of expression is evaluated , the second operand is evaluated if it is necessary.

Short circuit operators in c programming are &&(Logical AND), ||(Logical OR).

Logical AND:
In logical AND operator expression if the first operand is false then it is no need of evaluating the second operand.

Logical OR:
In Logical OR operator expression if the first operand is true then it is no need of evaluating the second operand.

AND operator example
OR operator example

Predict the output


extern int a;
int ss();
int main()
{
int a=10;
ss();
return printf("%d",a);
}
int ss()
{
return printf("%d",a);
}
int a=20;
Answer:
2010
1020
1010
Compilation Error

Predict the Output:


main()
{
float me = 1.1;
double you = 1.1;
if(me==you)
printf("shark selva");
else
printf("Matrix Developer");
}


shark selva
Matrix Developer


Difference between a string copy (strcpy) and a memory copy (memcpy)?

What is the difference between a string copy (strcpy) and a memory copy (memcpy)? When should each be used?


why??

why n++ executes faster than n+1?



Is these two programs same?


for (i=0;i<5;i++)
{
if(i%3==0)
continue;
}

i=0;
while(i<5)
{
if(i%3==0)
continue;
i++;
}

Answer:

Yes
No




Additon without Arithmetic Operators:

Here is the program which use bit wise operator and perform the addition operation. There is no arithmetic operator is used in this program.

int main()
{
int a,b,sum,carry;
printf("Enter the values");
scanf("%d %d",&a,&b);
sum=a^b;
carry=a&b;
while(carry!=0)
{

Program without Header File

is it possible to run the program without header file?  yes, it is possible.  consider the following program.

int main()
{
printf("hi");
return 0;
}
 It will work perfectly ,if you save the file.  But the concept is that while compiling itself ,compiler includes stdio.h header file automatically. 

0 comments:

Post a Comment