GeekInterview.com
Series: Subject: Topic:

C Interview Questions

Showing Questions 1 - 20 of 587 Questions
First | Prev | | Next | Last Page
Sort by: 
 | 

Write a program to convert numbers into words?For ex: 547five hundred and forty seven

Asked By: Preetham | Asked On: Oct 4th, 2006

Answered by: jbode on: Apr 24th, 2013

The following handles up to 32-bit integer values. Not the prettiest code in the world, but it works pretty well. Sample output: [fbgo448@n9dvap997]~/prototypes/numbers: ./numbers 1 one [fbgo448@n9...

Answered by: mm on: Apr 22nd, 2013

"c #include #include void pw(long,char[]); char *one[]={" "," one"," two"," three"," four"," five"," six"," seven","eight"," Nine"," ten"," eleven"," twelve"," thirteen"," fourteen...

What is the output of the following program:

Asked By: lalithakasiraj | Asked On: Dec 15th, 2012

Code
  1. int main()
  2. {
  3. char a = 120, b = 140;
  4. int i;
  5. i = a + b;
  6. printf("%d", i);
  7. return 0;
  8. }

a) 260 b) 0 c) -1 d) 1

Answered by: nitinshk1111 on: Apr 13th, 2013

it will be 4;
der is no any option unfortunately;
bcoz a=120 and b=140 but b can,t exceed 127. after 127 it will be -128,-127,-126.......up to -116;
so updated a and b will be 120, -116 respectively;
so final value will be 4:

Answered by: smkumar123 on: Apr 1st, 2013

a

Removing duplicate words from a string

Asked By: pro_learner | Asked On: Apr 6th, 2013

Code
  1. int main()
  2. {
  3.         char arr[1000];
  4.         char *temp=NULL;
  5.         char *temp1=malloc(100);
  6.         int len;
  7.         printf("enter the string:
  8. ");
  9.         gets(arr);
  10.         len=strlen(arr);
  11.         puts(arr);
  12.         printf("len:%d
  13. ",len);
  14.         temp=strtok(arr," ");
  15.        
  16.         if(temp!=NULL)
  17.                 strcpy(temp1,temp);
  18.        
  19.         while(temp!=NULL)
  20.         {
  21.                
  22.                 temp=strtok(NULL," ");
  23.                
  24.                 if(strstr(temp1,temp)==NULL)
  25.                 {
  26.                        
  27.                         strcat(temp1," ");
  28.                         strcat(temp1,temp);
  29.                        
  30.                 }
  31.         }
  32.         strcpy(arr,temp1);
  33.         printf("arr:%s",arr);
  34.         return 0;
  35. }
  36.  

This is giving me runtime error why ?

Answered by: jbode on: Apr 10th, 2013

You need to check that temp isnt null after the call to strtok() in the loop. See the attachment for a fix.

Code
  1. temp = strtok(NULL, " ");
  2.  
  3. if (temp != NULL && strstr(temp1,temp) == NULL)

What do you mean by "paridium"....?

Asked By: bcac2 | Asked On: Apr 8th, 2013

What is wild pointer?

Asked By: pbchaudhari | Asked On: Aug 21st, 2007

Answered by: chandu on: Apr 5th, 2013

wild pointer is a pointer which has not been initialized i.e point to nothing

Answered by: sunil on: Feb 20th, 2013

A pointer which does not hold any valid address is called wild pointer

Difference between printf and cprintf

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

What is the difference between cprintf and printf? Please explain in detail.

Answered by: Howard Lee Harkness on: Apr 4th, 2013

cprintf outputs to the console device.
fprintf outputs to a stream specified by the 1st parameter.

Answered by: Ravindra Kittad on: Dec 20th, 2012

printf outputs to the standard output stream (stdout)

fprintf goes to a file handle (FILE*)

sprintf goes to a buffer you allocated. (char*)

What will be output if you will execute following C code?

Asked By: lalithakasiraj | Asked On: Dec 15th, 2012

Code
  1.  #i ain()
  2. {
  3. float p=1,q=2,r=-2,a;
  4. a=avg(p,(q=4,r=-12,q),r);
  5. printf("%f",a); return 0;
  6. }
  7. float avg(float x,float y,float z)
  8. {
  9. return (x+y+z)/3;
  10. }

a) 1.000000 b) 0.333333 c) -2.333333 d) 1

Answered by: Howard Lee Harkness on: Apr 4th, 2013

The real answer is that any programmer who would write this kind of code should be given the opportunity to work for the competition.

The sequence expression (q=4,r=-12,q) evaluates to 4 (the last element), with the side-effect of assigning r the value -12. So, avg(1,4,-12) = -7/3 = -2.33...

Answered by: bavya on: Feb 15th, 2013

avg(1,-6,-2)/3 =-2.3333

Write a program to implement the fibonacci series

Asked By: Interview Candidate | Asked On: Jun 3rd, 2005

Star Read Best Answer

Editorial / Best Answer

Answered by: baseersd

View all answers by baseersd

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

Code
  1.  
  2. #include
  3. int main()
  4. {
  5. unsigned int i = 0, j = 0, sum = 1, num;
  6. printf("nEnter the limit for the series ");
  7. scanf("%d", &num);
  8. while (sum < num) {
  9. printf("%d ", sum);
  10. i = j;
  11. j = sum;
  12. sum = i + j;
  13. }
  14. getch();
  15. }
  16.  

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

Code
  1. #include<stdio.h>
  2. #include<conio.h>
  3. void main()
  4. {
  5. int pre=0,next=1,sum=0,n;
  6. clrscr();
  7. printf("enter the value of n:");
  8. scanf("%d",&n);
  9. while(pre<=n)
  10. {
  11. printf("the fibonacci series; %d
  12. ",pre);
  13. sum=pre+next;
  14. pre=next;
  15. next=sum;
  16. }
  17. getch();
  18. }

Answered by: madhusudan dadhich on: Jul 24th, 2012

limit:5
01123

We should not read after a write to a file without an intervening call to fflush(), fseek() or rewind()

Asked By: Interview Candidate | Asked On: Dec 10th, 2005

A) trueb) false

Answered by: sunil on: Mar 1st, 2013

A) True

Answered by: dasam on: Mar 30th, 2007

We cannot read the data using fread() function that was written in to file using fwrite() function. This is so beacause the file pointer (FILE* fp) that was passed as the argument of the fread() funct...

Write a program in C to find the 3*3 matrix multiplication

Asked By: mpriya | Asked On: Nov 13th, 2007

Answered by: Subhanjan Basu on: Apr 10th, 2012

Check this out:

Code
  1. int a[3][3],b[3][3],c[3][3];
  2.  
  3.         int i,j,k;
  4.        
  5.         printf("enter the elements in A matrix:
  6. ");
  7.         for(i=0;i<=2;i++)
  8.         {
  9.                 for(j=0;j<=2;j++)
  10.                 {
  11.                         scanf("%d",&a[i][j]);
  12.                 }
  13.         }
  14.  
  15.         printf("enter b matrix:
  16. ");
  17.         for(i=0;i<=2;i++)
  18.         {
  19.                 for(j=0;j<=2;j++)
  20.                 {
  21.                         scanf("%d",&b[i][j]);
  22.                 }
  23.         }
  24.  
  25.        
  26.         for(i=0;i<=2;i++)
  27.         {                    
  28.        
  29.                 printf("
  30. ");
  31.                 for(j=0;j<=2;j++)
  32.                 {
  33.        
  34.                         c[i][j]=0;
  35.                         for(k=0;k<=2;k++)
  36.                         {
  37.                                  c[i][j] = c[i][j]+a[i][k] * b[k][j];
  38.                         }
  39.                 }
  40.         }
  41.         printf("multiplication matrix is:
  42. ");
  43.         for(i=0;i<=2;i++)
  44.         {
  45.                 for(j=0;j<=2;j++)
  46.                 {
  47.                         printf("%d      ",c[i][j]);
  48.                 }
  49.                 printf("
  50. ");
  51.         }

Answered by: mskreddy0236 on: Dec 10th, 2007

Code
  1.  
  2. main()
  3. {
  4. int a[10][10],b[10][10],c[10][10]:
  5. int i,j,k;
  6. printf("enter the elements in A matrix");
  7. for(i=0;i<=5;i++)
  8.     for(j=0;j<+5;j++)
  9. {
  10. scanf("%d",&a[i][j]);
  11. }
  12. printf("enter b matrix");
  13. for(i=0;i<=5;i++)
  14.     for(j=0;j<+5;j++)
  15. {
  16. scanf("%d",&b[i][j]);
  17.  
  18.  
  19. }
  20. c[0][0]=0;
  21. for(i=0;i<=5;i++)
  22. {                    [  this is main logic ]
  23. for(j=0;j<=5;j++)
  24. {
  25. for(k=0;k<=5;k++)
  26. {
  27. c[i][j]=c[i][j]=c[k][j]+a[i][k]*b[k][j];
  28.  
  29. }
  30. }
  31. printf("multiplication matrix is");
  32. for(i=0;i<=5;i++)
  33. for(j=0;j<=5;j++)
  34. printf("%d",c[i][j]):
  35. }
  36.  

What is the output of the program

Asked By: tinass | Asked On: Dec 17th, 2012

Code
  1. #include<stdio.h>
  2. int main()
  3. {
  4.   printf("%c",*"abcde");
  5.  return 0;
  6. }

Answered by: nitin cahauhan on: Dec 28th, 2012

here in printf %c is consider for only a character not for a string so it will print only first letter or character of string i.e a

Answered by: Anik on: Dec 22nd, 2012

Answer is a

Language

Asked By: v s.n.reddy | Asked On: Dec 9th, 2012

What is the difference b/w C & Java?

Answered by: jbode on: Dec 26th, 2012

There are many differences beyond syntax. C compiles to a native binary, whereas Java compiles to a bytecode that is interpreted by a virtual machine (typically). C leaves a lot of details such as t...

What is the difference between getch() and getche()?

Asked By: harsha_yhvr | Asked On: Aug 6th, 2007

Answered by: SRIDHAR YADAV P.V. on: Dec 24th, 2012

Both getch() and getche() are used to read single character there is very little difference -getch() doesnt display output to screen if used without lvalue -getche() display output to screen even ...

What should be returned at line commented "//insert here" so that code returns numbers in fibonacci sequence?

Asked By: lalithakasiraj | Asked On: Dec 15th, 2012

Code
  1. #include <stdio.h>
  2. int fib(n){
  3. if (n <= 2)
  4. return 1;
  5. else
  6. // insert here
  7. }

a) return fib(n) + fin(n-1); b) return fib(n-1) + fin(n-2); c) return fib(n) + fin(n+1); d) return fin(n-1);

If a,b,c are int variables and a=2, b=4,c=3,d=5, what is the value of the expression

Asked By: Swati Goel | Asked On: Dec 1st, 2012

A/b/c*d-a+c*d/b-c. Justify your answer

Answered by: Noa on: Dec 14th, 2012

The answer is -2.
Expressions are calculated from left to right and so we have:
a/b=1, (a/b)/c=0 (rounding down).
c*d/b is also calculated the same way to give 3.
So -2+3-3 = -2

What is page thrashing?

Asked By: Interview Candidate | Asked On: Mar 6th, 2005

Some operating systems (such as UNIX or windows in enhanced mode) use virtual memory. Virtual memory is a technique for making a machine behave as if it had more memory than it really has, by using disk space to simulate ram (random-access memory). In the 80386 and higher intel cpu chips, and in most...

Answered by: amit1220 on: Dec 13th, 2012

Thrashing is caused by under allocation of the minimum number of pages required by a process, forcing it to continuously page fault. The system can detect thrashing by evaluating the level of CPU util...

Answered by: crimola on: Jan 8th, 2009

First of all there is a one sentence definition of Page Thrashing (I believe someone posted a similar answer here):Page Thrashing only comes about when you use Virtual Memory which requires an MMU and...

What change is required in the following program so that its output becomes 3,6,11,20,37,......1034?

Asked By: Swati Goel | Asked On: Dec 1st, 2012

Code
  1. #include<stdio.h>
  2. #include<math.h>
  3. int main()
  4. {
  5. int a=1,r=2,i;
  6. for (i=0;i<=10;i++)
  7. printf(",%d ", a * pow(r,i));
  8. return 0;
  9. }

Answered by: prakash pankaj on: Dec 1st, 2012

Code
  1. #include<stdio.h>
  2. #include<conio.h>
  3. int main()
  4. {
  5. int r=2,i,a;
  6. for(i=1,a=1;a<10,i<10;a++,i++)
  7. {
  8. printf("%d",(a+pow(r,i));
  9. }
  10. return 0;
  11. }

Find the errors in the following program:

Asked By: Swati Goel | Asked On: Dec 1st, 2012

Code
  1. # include<stdio.h>
  2. int main()
  3. {
  4. printf("Learning C is not
  5. a difficult task");
  6. return();
  7. }

Answered by: prakash pankaj on: Dec 1st, 2012

Return should contain return(0) because return type of main is int.

What is the type of the variable b in the following declaration? #define floatptr float* floatptr a,b; a) float b) float pointer c) int d) int pointer

Asked By: Interview Candidate | Asked On: Sep 9th, 2005

Answered by: shivprasad on: Nov 2nd, 2012

b) float pointer

Answered by: jbode on: Oct 29th, 2012

b is a plain float.

FLOATPTR a,b; expands to float* a,b;, which is *parsed* as float (*a),b;. The * is bound to the declarator, not the type specifier, so only a is declared as a pointer to float.

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

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.