GeekInterview.com
Series: Subject: Topic:

C Interview Questions

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

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: rams7 on: May 21st, 2012

4 5 6 7 8 9 10

Answered by: Amit Jain on: Mar 25th, 2012

Answer is 3

Why integer range -32768 to 32768

Asked By: Ramkesh poshwal | Asked On: Apr 12th, 2012

Why integer range -32768 to 32768 and actual meaning of storage size 2 bytes ?

Answered by: Varun Pratap Singh on: May 15th, 2012

In C language, int takes 2 bytes. Now 2 bytes mean 16 bits. One bit out of these 16 bits is for sign (+ or -) of integer. So, remaining 15 bits will store data in form of 0 and 1. The maximum value in...

C is not platform dependent.Why?

Asked By: Parul Sharma | Asked On: Jul 12th, 2011

We know that C is not platform independent.But if we make a program on a operating system and copy the same program on other os without any changes then this program will run after compiling and will give the same answer. so if same program will run on other os then why C is not platform independent.

Answered by: Ramesh Yadav on: May 4th, 2012

C is not platform dependent because it does not generate the uniform executables.
suppose if we have build C code and generated binary in Windows and this same binary will not work on Linux.

Answered by: jbode on: Oct 3rd, 2011

It is true that *some* programs can be compiled on other systems without any changes and produce the same outputs. "Hello, World" should work everywhere with no changes. However, such trivially port...

How can you determine the maximum value that a numeric variable can hold?

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

For integral types, on a machine that uses two’s complement arithmetic (which is just about any machine you’re likely to use), a signed type can hold numbers from –2(number of bits – 1) to +2(number of bits – 1) – 1. An unsigned type can hold values from 0 to +2(number of bits) – 1. For instance, a...

Answered by: Jimmy Jack on: Apr 25th, 2012

Code
  1. #include
  2. #include
  3.  
  4. template T get_min_value(void)
  5. {
  6.     return (T) (1 << ((sizeof(T) << 3) - 1));
  7. }
  8.  
  9. template T get_max_value(void)
  10. {
  11.     return (~(T) 0 - get_min_value());
  12. }
  13.  
  14. template T get_umin_value(void)
  15. {
  16.     return (T) 0;
  17. }
  18.  
  19. template T get_umax_value(void)
  20. {
  21.     return (~(T) 0);
  22. }
  23.  
  24. int main()
  25. {
  26.     std::cout << "minmum signed integer - " << get_min_value() << std::endl;
  27.     std::cout << "maxmum signed integer - " << get_max_value() << std::endl;
  28.     std::cout << "minmum unsigned integer - " << get_umin_value() << std::endl;
  29.     std::cout << "maxmum unsigned integer - " << get_umax_value() << std::endl;
  30.  
  31.     std::cout << "minmum signed short - " << get_min_value() << std::endl;
  32.     std::cout << "maxmum signed short - " << get_max_value() << std::endl;
  33.     std::cout << "minmum unsigned short - " << get_umin_value() << std::endl;
  34.     std::cout << "maxmum unsigned short - " << get_umax_value() << std::endl;
  35. }
  36.  
  37.  

Answered by: VENU BABU on: Oct 7th, 2011

first include limits.h
in that so many variables to find max and min value that can hold by any data type
for ex: INT_MAX,INT_MIN for integer and so on.......

C program for pyramid

Asked By: vrijesh28 | Asked On: Dec 20th, 2007

What will be the code in C to get the following output?A b C d e f g f e d C b aa b C d e f f e d C b aa b C d e e d C b aa b C d d C b aa b C C b aa b b aa a

Answered by: Jimmy Jack on: Apr 25th, 2012

Code
  1. #include <iostream>
  2. #include <fstream>
  3.  
  4. void display_sequence2(int depth)
  5. {
  6.     int output_count = 0;
  7.     for (int count = depth - 1; count >= 0; --count) {
  8.         for (int index = 0; index <= count; ++index)
  9.             std::cout << (char) ((((output_count++ == 0) || (index == 2)) ? A : a) + index) << " ";
  10.         for (int index = (count == (depth - 1)) ? count - 1 : count; index >= 0; --index) {
  11.             std::cout << (char) ((((output_count++ == 0) || (index == 2)) ? A : a) + index);
  12.             if (index > 0)
  13.                 std::cout << " ";
  14.         }
  15.     }
  16. }
  17.  
  18. int main()
  19. {
  20.     display_sequence2(7);
  21. }
  22.  

Answered by: Gaurav Bhadauria on: Oct 13th, 2011

Code
  1. int i, j, k;
  2. char a[] = { 'A', 'B', 'C', 'D', 'E', 'F', 'G' };
  3.  
  4. for (i = 0; i < 7; i++) {
  5.     for (k = 0; k < 7 - i; k++)
  6.         printf("%c ", a[k]);
  7.     for (j = 7 - (i + 1); j >= 0; j--)
  8.         printf("%c ", a[j]);
  9.     printf("n");
  10. }
  11.  

Write a function reverse which takes a string s as a parameter and prints out it reverse.

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

Example:reverse (hello) prints out (olleh)

Answered by: Nitesh Khandelwal on: Feb 29th, 2012

Code
  1.  
  2. void reverse(char *str)
  3. {
  4.     int i = 0;
  5.     for (i = 0; str[i] !=; i++) {
  6.         printf("%c", str[i]);
  7.         getch();
  8.     }
  9.  

Answered by: Lokesh M on: Feb 14th, 2012

Try this

Code
  1. void reverse (int idx, char *str ) {
  2.      if (--idx < 0 ) {
  3.           return ;
  4.      } else {
  5.           putchar ( *(str + idx) ) ;
  6.           reverse (idx, str) ;
  7.      }
  8. }

How to reverse a sentence with C program.

Asked By: a | Asked On: Sep 13th, 2005

Answered by: Harish on: Mar 21st, 2012

"c void main() { char *chStrptr = "Hi This is Harish"; While(*ChStrPtr != /0) { LenOfStr++ chStrPtr++; } do { while(*chStrPtr != ) { chStrPtr--; LenOfStr...

Answered by: sachin on: Dec 13th, 2011

I think you should use reverse string programme. You can store it an array and then run a loop.

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

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: mahamad on: Apr 19th, 2012

Code
  1. #include<stdio.h>
  2. #include<conio.h>
  3. main()
  4. {
  5. int i,a=0,b=1;
  6. while(i<=9)
  7. {
  8. printf("%d ",a);
  9. printf("%d ",b);
  10. a=a+b;
  11. b=b+a;
  12. i++;
  13. }
  14. getch();
  15. return 0;
  16. }

Answered by: MANUKUNDLOO on: Sep 8th, 2011

Code
  1. int main()
  2. {
  3.   int i=-1,j=1,sum=0,num;
  4.   printf("ENTER THE LIMIT OF THE SERIES: ");
  5.   scanf("%d",&num);
  6.   while(sum<num)
  7.     {
  8.        sum=i+j;
  9.        i=j;
  10.        j=sum;
  11.        printf("%d",sum);
  12.     }
  13.  getch();
  14. }

What is the output of this C code?

Asked By: kriti aggarwal | Asked On: Apr 14th, 2012

Code
  1. #include<stdio.h>
  2. void main()
  3. {
  4. printf(5+"fascimile");
  5. }
  6.  

Answered by: Mohammed AL-khatib on: Apr 17th, 2012

mile

because it will skip starting 5 letters

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.  

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

Asked By: Interview Candidate | Asked On: Jul 7th, 2005

True

Answered by: Sandhya.Kishan on: Mar 28th, 2012

True, we should not be able to read a file after writing in that file without calling the given functions because if the file was open for writing and IF the last operation was an output operation, th...

What is a method?

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

A way of doing something, especially a systematic way; implies an orderly logical arrangement (usually in steps)

Answered by: Sandhya.Kishan on: Mar 28th, 2012

A method is a subroutine to a class or it is a set of code referred by a name, these methods can be invoked or called at any part of the program to execute their set of codes.At runtime,methods have access to data stored in an instance of the class.A class can contain more than one methods.

Differentiate between a linker and linkage? 

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

A linker converts an object code into an executable code by linking together the necessary build in functions. The form and place of declaration where the variable is declared in a program determine the linkage of variable.

Answered by: Sandhya.Kishan on: Mar 28th, 2012

Linker are used to convert the object code to executable codes where as linkage to a variable determines the deceleration of the variables declared in the given program.

What is storage class and what are storage variable ?

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

A storage class is an attribute that changes the behavior of a variable. It controls the lifetime, scope and linkage.There are five types of storage classes 1)auto   2)static   3)extern  4)register   5)typedef

Answered by: Sandhya.Kishan on: Mar 28th, 2012

Storage class are used to define the lifetime and scope of a function or available.There are four storage classes namely auto,static,register and extern storage classes. Storage variables are the vari...

C program exectuion stages

Asked By: shyamkumar1221 | Asked On: Nov 12th, 2010

Briefly explain the stages in execution of C program ?How are printf and scanf statements statements being moved into final executable code?

Answered by: Sandhya.Kishan on: Mar 28th, 2012

There are seven stages of execution
1. Forming the goal
2. Forming the intention
3. Specifying an action
4. Executing the action
5. Perceiving the state of the world
6. Interpreting the state of the world
7. Evaluating the outcome

What is indirection?

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

If you declare a variable, its name is a direct reference to its value. If you have a pointer to a variable, or any other object in memory, you have an indirect reference to its value.  

Answered by: Sandhya.Kishan on: Mar 28th, 2012

Indirection operator (denoted by *) is a unary operator which include pointer variables. It operates on a pointer variable,and returns a value equivalent to the value at the pointer address. Example:...

Is it better to use malloc() or calloc()?

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

Both the malloc() and the calloc() functions are used to allocate dynamic memory. Each operates slightly different from the other. Malloc() takes a size and returns a pointer to a chunk of memory at least that big:  void *malloc( size_t size ); calloc() takes a number of elements, and the size...

Answered by: Sandhya.Kishan on: Mar 28th, 2012

Malloc() and calloc() are used to allocate memory blocks dynamically.malloc() is a bit faster since it does not initialize the allocated memory blocks to as it is done by calloc() function.Hence it is better to use malloc() then calloc().

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

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: mukesh kumar on: Mar 25th, 2012

Code
  1. int main(){
  2. int a,b;
  3. printf("Enter the two numbers:
  4. ");
  5.  
  6. scanf("%d",&a);
  7. scanf("%d",&b);
  8. printf("Sum is: %d",add(a,b));
  9. }

Answered by: sravan on: Aug 20th, 2011

Code
  1.          #include<iostream.h>
  2.          void main()
  3.  {
  4.       int i=20,j=30,m,n;
  5.                          m=i,n=j;
  6. if(i<j)
  7. {
  8.           for(i=1;i<=m;i++)
  9.                         j++;
  10.          cout<<j;
  11. }
  12. else
  13. {
  14.         for(j=1;j<=n;j++)
  15.                  i++;
  16.   cout<<i;
  17. }
  18.  }

What ithe difference between a end of line and eof while giving the inputs during run time?

Asked By: Karthik_p | Asked On: Nov 11th, 2007

Answered by: pawandeep on: Mar 24th, 2012

end of file is a function which returns zero value at end of file... EOF is a deliminator

Answered by: baseersd on: Nov 19th, 2007

End of Line refers to the 'n'( new line character). It will perform operations till it come across 'n'.

EOF refers to End of File. It is the last character in the file.(if it is not empty). If the file is empty then only EOF will be present.
Some compilers give its value as -1.

Write a program to identify a duplicate value in vector ?

Asked By: ghousia razvi | Asked On: Jan 13th, 2012

Answered by: Sandhya.Kishan on: Mar 20th, 2012

"c void rmdup(int *array, int length) { int *current, *end = array + length - 1; for (current = array + 1; array < end; array++, current = array + 1) { while (current < ...

First | Prev | | Next | Last Page

 

 

Connect

twitter fb Linkedin GPlus RSS

Ads

Interview Question

 Ask Interview Question?

 

Career Counselling

 Have Career Question?

 Ask Chandra

 Ask Only Career questions.

Follow us:
 

Latest Questions

Ads

Interview & Career Tips

Get invaluable Interview and Career Tips delivered directly to your inbox. Get your news alert set up today, click "Subscribe".