GeekInterview.com
Series: Subject: Topic:

C Interview Questions

Showing Questions 21 - 40 of 587 Questions
First | Prev | | Next | Last Page
Sort by: 
 | 

Cprintf vs printf

Asked By: Ruhani Chawlia | Asked On: Oct 27th, 2012

Cprintf is defined to send formatted output to the text window on the screen. And printf directs its output to the stdout. What is the difference between stdout and a text window then? Does the screen serve differently while using cprintf and printf? Please explain

What would be the output of the following program? main() { int y=128; const int x=y; printf("%d",x); } a) 128 b) garbage value c) error d) 0

Asked By: Interview Candidate | Asked On: Aug 13th, 2005

Answered by: ...uzma... on: Oct 4th, 2012

128

Answered by: Ashok Kumar Orupalli on: Sep 4th, 2012

Answer is a)128. Here we are not modifying const value. We are just assigning value to const variable.

Language and scripting language

Asked By: koppolusairam | Asked On: Sep 5th, 2012

Explain the difference between language and scripting language?

Answered by: ...uzma... on: Oct 4th, 2012

The origin of the term was similar to its meaning in "a movie script tells actors what to do": a scripting language controlled the operation of a normally-interactive program, giving it a sequence of ...

Answered by: jbode on: Sep 12th, 2012

"Scripting" language *usually* implies a language thats interpreted as opposed to compiled, with lots of high-level operations for file manipulation, pattern matching, job management, etc. and geared ...

Pre and post increment operators

Asked By: Ruhani Chawlia | Asked On: Jul 28th, 2012

Why does ++i * ++i give 49 when i=5?

Answered by: Jaspal on: Sep 27th, 2012

it increments i by 1i.e i becomes 6 in first subexpression and becomes in 7 in second subexpression.finally 42 is answer

Answered by: Amita Negi on: Sep 6th, 2012

Priority of pre increment is high so:
1. firstly ++i is executed then i=6;
2. then again ++i is executed and i=7;
3. and then the multiplication is done so i*i or 7*7 is 49.

Break statement

Asked By: alokkrbhatt | Asked On: Jul 30th, 2010

What is the break statement used for?1. To quit the program.2. To quit the current iteration.3. To stop the current iteration and begin the next iteration.4. None of the above.

Answered by: preeti jain on: Sep 26th, 2012

to quit the current iteration. i.e. jump out of the loop.

Answered by: aditya pathak on: Sep 21st, 2012

3. To stop the current iteration and begin the next iteration.

Can more than one main() exist in the same program??

Asked By: rekhaty | Asked On: Jun 2nd, 2012

Answered by: dhruv on: Sep 25th, 2012

yes, it is called recursion

Answered by: Ashok Kumar Orupalli on: Sep 4th, 2012

Only one main main function is allowed. But you can call that main function n number of times.

Code
  1. void main()
  2. {
  3.     static int a;;
  4.     printf("%d",a);
  5.     printf(main());
  6. }

Enter key carriage return or linefeed?

Asked By: Ruhani Chawlia | Asked On: Jul 10th, 2012

When we press enter to end the program and press alt+f5 to see the output again, we see that the getche() function places the cursor at the beginning of the line. So, does the enter key specify carriage return in this case. But while entering output, it works as a newline character... Please explain...

Answered by: AnSi on: Sep 8th, 2012

Enter key is line feed.

A program in C using void pointer

Asked By: KRIPA SHANKAR | Asked On: Jul 8th, 2012

Code
  1. #include<stdio.h>
  2. #include<conio.h>
  3. int main()
  4. {
  5.  int a=10;
  6.  void *p;
  7.  p=&a;
  8.  clrscr();
  9.  printf("%u",*p);
  10.  getch();
  11.  return;
  12. }

I know that this program is wrong as error is shown on compiling it. Anyone please provide a simple program using Void pointer in C. Thanks in advance :)

Answered by: Ashok Kumar Orupalli on: Sep 3rd, 2012

You have to typecast void pointer to int as *(int*)p;

Code
  1. #include<stdio.h>
  2. #include<conio.h>
  3. int main()
  4. {
  5.  int a=10;
  6.  void *p;
  7.  p=&a;
  8.  clrscr();
  9.  printf("%u",*(int*)p);
  10.  getch();
  11.  return 0;
  12. }

Answered by: Sereche on: Jul 8th, 2012

Your error is on line 9, where youve attempted to dereference a pointer to void (the expression *p). You can only dereference typed pointers. The solution you are probably looking for would be to repl...

Print number of distinct characters in a string.

Asked By: levis | Asked On: Nov 23rd, 2011

How do I implement a C program that reads a string and prints a table with the number of occurrences of each character in the string. ex: rubber. R = 2, u = 1, b = 2, e = 1.

Answered by: jbode on: Aug 31st, 2012

Simple, fairly brain-dead example. Assumes any input characters fall into the range [0...CHAR_MAX). "c #include #include #include int main(int argc, char **argv) { int coun...

Getch function declaration

Asked By: Ruhani Chawlia | Asked On: Jul 10th, 2012

Can you please explain the declaration of getch() function that is "int getch(void)"? i have the doubt that if its return type is int, why is the character typed from the keyboard is displayed as it is? It should be displayed in its ascii value. Also, what does void as parameter in this function stand...

Answered by: jbode on: Aug 31st, 2012

In C, all the character-oriented functions (getc, fgetc, getchar, etc.) return int instead of char, mainly to support an out-of-band value for EOF (an integer expression with a negative value).

The "void" in the parameter list indicates that the function takes no parameters.

Sum of two numbers without using arithmetic operators

Asked By: meda_reddy | Asked On: Jul 15th, 2008

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

Star Read Best Answer

Editorial / Best Answer

Answered by: jintojos

View all answers by jintojos

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;
}

Answered by: mahamad on: Jun 14th, 2012

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

Print colors with printf

Asked By: shvia | Asked On: Sep 27th, 2011

Is it possible to print colors with printf statements ?

Answered by: Prashant Shetty on: Aug 17th, 2012

include conio.h header file and textcolor(int value) function and dont forget to use cprintf statement : ex:

Code
  1. textcolor(2);
  2. cprintf("hell world");
  3.  

now hello world will be displayed in yellow color

Answered by: jbode on: Jun 3rd, 2012

Not directly. The printf function simply sends formatted text to the output stream. However, with some terminals, you can send control codes as part of the formatted text, and these control codes ca...

Output of the C program

Asked By: shubhangi | Asked On: Aug 30th, 2011

What is the output of the following code?

Code
  1.  
  2. #include<stdio.h>
  3. void main()
  4. {
  5.    int s=0;
  6.    while(s++<10)
  7.    {
  8.       if(s<4 && s<9)
  9.          continue;
  10.       printf("
  11. %d      ",s);
  12.    }
  13. }
  14.  

1) 1 2 3 4 5 6 7 8 9
2) 1 2 3 10
3) 4 5 6 7 8 9 10
4) 4 5 6 7 8 9

Answered by: Nupur Boral on: Aug 16th, 2012

Ans:3 s++ means-first s=0 then s=s+1.so checking the initial value of s & then increment the value of s.In this way continuing this process & print the value of s.

Answered by: Ravindra Kumar saxena on: Jul 25th, 2012

45678910

Function syntax

Asked By: ak.nextptr | Asked On: Jul 31st, 2012

String abc = showdata()["hello"]; can somebody explain what is use of ["hello"] after function call?

Answered by: jbode on: Aug 6th, 2012

C doesn't have a String data type, unless that supposed to be a typedef for something. Having said that, I think this is taking advantage of the fact that array indexing in C is commutative; IOW, "...

Read specified number of elements

Asked By: shamina sasankan | Asked On: Dec 15th, 2010

What function will read a specified number of elements from a file?

Answered by: kiran.eemuru on: Aug 1st, 2012

fread() function will read a specified number of elements from a file .

Answered by: rocking.piyush on: Feb 22nd, 2011

its the read() function

the syntax is

int bytes = (fp, buf,1);

First argument is the source file, second argument is the address of the buffer and the third argument is the maximum number of bytes we want to read.

It returns the number of bytes actually read.

Accept an amount in rupees (indian currency ) from the user...

Asked By: cguyc | Asked On: Jul 20th, 2012

....And find the minimum number of notes to form that amount. the denominations are 500,100,50,20,10,5,2,1 rupee. using any loop!!

Answered by: Bincy Roy on: Jul 30th, 2012

"c #include int main(){ int amount,no_hun,no_fifty,no_ten,no_five,no_two,no_one,total_notes; printf(" Enter the amount: "); scanf("%d",&amount); no_hun=amount/100; amount=amoun...

Accept two numbers from the user...

Asked By: cguyc | Asked On: Jul 20th, 2012

...And multiply these two numbers without using the multiplication operator! using any loop!

Answered by: Delbin on: Jul 22nd, 2012

Code
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3. main()
  4. {
  5.         int a,b,result=0;
  6.         scanf("%d%d",&a,&b);
  7.         while(a)
  8.         {
  9.                 result=result+b;
  10.                 a--;
  11.         }
  12.         printf("%d
  13. ",result);
  14. }

Answered by: Er.Kunal on: Jul 22nd, 2012

I have included the code herein for u."c //Program for Multiplication without using multiplication operator written by Er.Kunal #include #include void main() { int multiplican...

Write a program to accept 20 numbers from the user

Asked By: cguyc | Asked On: Jul 20th, 2012

And count how many positive and how many negative and 0 numbers were entered!! pls

Answered by: delbin on: Jul 22nd, 2012

Code
  1. #include<stdio.h>
  2.  
  3. main()
  4. {
  5.         int a[20],i;
  6.         int pos,neg,zero;
  7.  
  8.         pos=neg=zero=0;
  9.  
  10.         for(i=0;i<5;i++)
  11.         {
  12.                 scanf("%d",&a[i]);
  13.                 if(a[i]>0)
  14.                         pos++;
  15.                 else if(a[i]<0)
  16.                         neg++;
  17.                 else
  18.                         zero++;
  19.         }
  20.         printf("+:%d -:%d 0:%d
  21. ",pos,neg,zero);
  22.  
  23. }

C compiler dependency

Asked By: arunkindra | Asked On: Jul 20th, 2012

Some questions answers are compiler dependent..So correct it, as in my test I observed the sizeof int is 2 bytes which was in 16bit compiler like turbo. Now world has moved to 32 bits, even 64 bits will coming near soon, so change ur test ans....

Write a function reverse which takes a strings as a parameter and prints it out in reverse.

Asked By: yong ha | Asked On: Dec 3rd, 2011

Example:reverse (hello) prints out (olleh)

Answered by: mahamad on: Jun 14th, 2012

Code
  1. #include<stdio.h>
  2. #include<conio.h>
  3. #include<string.h>
  4. main()
  5. {
  6. char s[100];
  7. int i;
  8. printf("Enter ANy String:=>");
  9. scanf("%s",&s);
  10. printf("-----------Reverse String is---------------
  11. ");
  12. for(i=strlen(s);i>=1;i--)
  13. {
  14.       printf("%c",s[i]);
  15. }
  16. getch();
  17. return 0;
  18. }

Answered by: ankur on: Jun 7th, 2012

Code
  1. #include<stdio.h>
  2. #include<string.h>
  3. void main()
  4. {
  5. int a,i;
  6. char b[100];
  7. char s[100]="in this world let there be a name and fame to those who can";
  8. a=strlen(s);
  9. for(i=0;i<=s;i++)
  10. {
  11. b[i]=s[a-i];
  12. }
  13. printf("%s",b);
  14. }

First | Prev | | Next | Last Page

 

 

Ads

Connect

twitter fb Linkedin GPlus RSS

Ads

Interview Question

 Ask Interview Question?

 

Latest Questions

Ads

Interview & Career Tips

Get invaluable Interview and Career Tips delivered directly to your inbox. Get your news alert set up today, Once you confirm your Email subscription, you will be able to download Job Inteview Questions Ebook . Please contact me if you there is any issue with the download.