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 >> Code-Snippets >> Programming-Code >> C-Code
 
 


 

Back to Questions Page
 
Question
How we print the table of 3 using for loop in c 
programing?
Rank Answer Posted By  
 Question Submitted By :: Rajesh Verma
I also faced this Question!!   © ALL Interview .com
Answer
int i;
for(i=1;i<=10;i++)
{
      i=i*3;
      printf("%d",i);
}
 
0
Chitra
 
 
Answer
int i,no;
for(i=1;i<=10;i++)
{
      no=i*3;
      printf("%d",no);
}
 
0
Chitra
 
 
Answer
for(i=1;i<=10&&printf("3*%d=%d",i,3*i);i++);
 
0
Teja
 
 
 
Question
main()
      {	
      char a[4]="HELL";
      printf("%s",a);
      }
Rank Answer Posted By  
 Question Submitted By :: Susie
This Interview Question Asked @   Wipro
I also faced this Question!!   © ALL Interview .com
Answer
Answer :
HELL%@!~@!@???@~~!

      Explanation:
The character array has the memory just enough to hold the
string “HELL” and doesnt have enough space to store the
terminating null character. So it prints the HELL correctly
and continues to print garbage values till it 	accidentally
comes across a NULL character.
 
0
Susie
 
 
Question
char *someFun1()

		{

		char temp[ ] = “string";

		return temp;

		}

		char *someFun2()

		{

		char temp[ ] = {‘s’, ‘t’,’r’,’i’,’n’,’g’};

		return temp;

		}

		int main()

		{

		puts(someFun1());

		puts(someFun2());

		}
Rank Answer Posted By  
 Question Submitted By :: Susie
I also faced this Question!!   © ALL Interview .com
Answer
Answer : 

	Garbage values.

Explanation:

	Both the functions suffer from the problem of dangling
pointers. In someFun1() temp is a character array and so the
space for it is allocated in heap and is initialized with
character string “string”. This is created dynamically as
the function is called, so is also deleted dynamically on
exiting the function so the string data is not available in
the calling function main() leading to print some garbage
values. The function someFun2() also suffers from the same
problem but the problem can be easily identified in this case.
 
0
Susie
 
 
Question
char *someFun()

		{

		char *temp = “string constant";

		return temp;

		}

		int main()

		{

		puts(someFun());

		}
Rank Answer Posted By  
 Question Submitted By :: Susie
I also faced this Question!!   © ALL Interview .com
Answer
Answer : 

		string constant 

Explanation:

		The program suffers no problem and gives the output
correctly because the character constants are stored in
code/data area and not allocated in stack, so this doesn’t
lead to dangling pointers.
 
0
Susie
 
 
Question
Printf can be implemented by using  __________ list.
Rank Answer Posted By  
 Question Submitted By :: Susie
I also faced this Question!!   © ALL Interview .com
Answer
Answer :  

		Variable length argument lists
 
0
Susie
 
 
Question
main()

      { 

		int a=10,*j;

      	void *k; 

		j=k=&a;

        	j++;  

		k++;

        	printf("\n %u %u ",j,k);

      }
Rank Answer Posted By  
 Question Submitted By :: Susie
I also faced this Question!!   © ALL Interview .com
Answer
Answer :  

		Compiler error: Cannot increment a void pointer

      Explanation:

Void pointers are generic pointers and they can be used only
when the type is not known and as an intermediate address
storage type. No pointer arithmetic can be done on it and
you cannot apply indirection operator (*) on void pointers.
 
0
Susie
 
 
Question
main()

      {

      char a[4]="HELLO";

      printf("%s",a);

      }
Rank Answer Posted By  
 Question Submitted By :: Susie
I also faced this Question!!   © ALL Interview .com
Answer
Answer :  

		Compiler error: Too many initializers

      Explanation:

The array a is of size 4 but the string constant requires 6
bytes to get stored.
 
0
Susie
 
 
Question
Is this code legal?

      int *ptr; 

ptr = (int *) 0x400;
Rank Answer Posted By  
 Question Submitted By :: Susie
I also faced this Question!!   © ALL Interview .com
Answer
Answer :  

		Yes

      Explanation:

      The pointer ptr will point at the integer in the
memory location 0x400.
 
0
Susie
 
 
Question
void main()

      {

      char ch;

      for(ch=0;ch<=127;ch++)

      printf(“%c   %d \n“, ch, ch);

      }
Rank Answer Posted By  
 Question Submitted By :: Susie
I also faced this Question!!   © ALL Interview .com
Answer
Answer :  

      	Implementaion dependent

      Explanation:

The char type may be signed or unsigned by default. If it is
signed then ch++ is executed after ch reaches 127 and
rotates back to -128. Thus ch is always smaller than 127.
 
0
Susie
 
 
Question
void main()

      {

      int i=10, j=2;

      int *ip= &i, *jp = &j;

      int k = *ip/*jp;

      printf(“%d”,k);

      }
Rank Answer Posted By  
 Question Submitted By :: Susie
I also faced this Question!!   © ALL Interview .com
Answer
Answer :  

      Compiler Error: “Unexpected end of file in comment
started in line 5”.

      Explanation:

The programmer intended to divide two integers, but by the
“maximum munch” rule, the compiler treats the operator
sequence / and * as /* which happens to be the starting of
comment. To force what is intended by the programmer,

      int k = *ip/ *jp;	

      // give space explicity separating / and * 

      //or

      int k = *ip/(*jp);

      // put braces to force the intention  

      will solve the problem.
 
0
Susie
 
 
Question
Which version do you prefer of the following two,

      1) printf(“%s”,str); 	// or the more curt one

      2) printf(str);
Rank Answer Posted By  
 Question Submitted By :: Susie
I also faced this Question!!   © ALL Interview .com
Answer
Answer :  & Explanation:

Prefer the first one. If the str contains any  format
characters like %d then it will result in a subtle bug.
 
0
Susie
 
 
Question
char inputString[100] = {0};

      To get string input from the keyboard which one of the
following is better?

      	1) gets(inputString)

      	2) fgets(inputString, sizeof(inputString), fp)
Rank Answer Posted By  
 Question Submitted By :: Susie
I also faced this Question!!   © ALL Interview .com
Answer
Answer :  & Explanation:

The second one is better because gets(inputString) doesn't
know the size of the string passed and so, if a very big
input (here, more than 100 chars) the charactes will be
written past the input string. When fgets is used with stdin
performs the same operation as gets but is safe.
 
0
Susie
 
 
 
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