GeekInterview.com
Answered Questions

C structures

Asked By: ujvala | Asked On: Jan 22nd, 2008

Is structure a value type or a reference type? Why?

Answered by: karthik_jeeva on: May 5th, 2008

Answer is Structure is Value type

Answered by: baseersd on: Jan 24th, 2008

Hi Ujvala,I am little bit confused with the question, Are you asking like1)Calling the function with structure as a parameter, whether changes  value of structure or not2)Passing of structure can...

What is the relation between array name and an element number.

Asked By: varun | Asked On: Nov 15th, 2007

Answered by: jintojos on: Jun 9th, 2008

Array name is the base address of the aaray. By using this base address we can refer to the array elements. that is a[0] means "base address + 0th" element. that is array element number is the distence from the base address to the specified data 

Answered by: Joe on: Nov 20th, 2007

The relationship between an array element and the elements index number is as follows.     1. The array name by itself is a constant pointer to the first element of the a...

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.

C program to count numbers of positive and negative numbers

Asked By: Tai | Asked On: Oct 12th, 2007

Write a C program using arrays to count the numbers of positive and negative numbers which accepts the inputs as "size of the array" & "elements of the array" and outputs as "number of negative numbers in an array are" & "numbers of positive numbers in an array are" ?

Answered by: kesineni on: Jul 12th, 2009

#include <stdio.h>main(){   int a[] = { 1,-3,-5,-4,-9,2,8};   int len,i,val;   int npos=0, nneg=0;   len = sizeof(a)/sizeof(a[0]);   printf(&quo...

Answered by: jintojos on: Jun 18th, 2008

#include<conio.h>#include<stdio.h>void main()  {      int *arr,num,i=0,pos=0,neg=0;      clrscr();      prin...

Difference between void pointer and generic pointer?

Asked By: srinivasarao | Asked On: Oct 12th, 2007

Answered by: abhimanipal on: Jul 5th, 2009

I just want to make a small point.When you assign an array to a pointer, you can't put an & signint arr[5]={1,2,3},*p1;p1=arr;This will workint arr[5]={1,2,3},*p1; p1=&arr; error: can...

Answered by: pradeep Jadhav on: Oct 13th, 2008

void pointer can be used to store address of any type of variable e.g.int,float,char,but generic pointer can't.

Is nesting of conditional operator( ? : ) possible? If no then why? If yes then write down the program to find the greatest of three number?

Asked By: sanjeev | Asked On: Oct 11th, 2007

Yes, nesting of conditional operator is possible .Write down the program yourself.

Answered by: baseersd on: Oct 31st, 2007

Conditional operator can be nested. But it is not recommended as there are chances of getting confuse with its statements. Here is the code for nesting of conditional operator.#include <stdio.h>...

What is the use of template in c++?

Asked By: vishal | Asked On: Sep 17th, 2007

Answered by: amandahh on: Nov 29th, 2007

With templates, you do not have to repeat the entire codes for different types.

Answered by: baseersd on: Sep 18th, 2007

It makes the program more general.just take as an example,If we have written a program to find the binary sort of integers, then we can sort only integers. At some point of time i want to sort charact...

How many ways a function can be used according to the argument list and return types? Explain

Asked By: sachipatnaik2008 | Asked On: Sep 12th, 2007

Answered by: kamal7725 on: Nov 30th, 2007

That's true overloading in not possible in C.But in C++ function can be varied depending on its argument not on the return type.because, if there are two function with the same name having same ar...

Answered by: baseersd on: Sep 18th, 2007

In C , overloading of the function is not possible.

Why scanf("%d",&n) and gets(string) don't work together?

Asked By: pbchaudhari | Asked On: Sep 10th, 2007

Answered by: kbjarnason on: Jul 1st, 2010

The solution is *NOT*, as another writer posted, to use fflush(stdin), because fflush is defined only for *output* streams, and stdin is not an output stream.  Yes, your implementation may suppor...

Answered by: baseersd on: Sep 18th, 2007

This is a general problem of the keyboard buffer. When scanf("%d",&n); is used and when an input is entered, the newline character("n") along with the input is stored in buffer...

What do you mean by #pragma once

Asked By: pbchaudhari | Asked On: Sep 10th, 2007

Answered by: baseersd on: Sep 18th, 2007

#pragma once is a non-standard but widely supported preprocessor directive designed to cause the current source file to be included only once in a single compilation. Thus, #pragma once serves th...

Can we include a header file in another header file?

Asked By: sanjay ujjainkar | Asked On: Sep 9th, 2007

Answered by: baseersd on: Sep 17th, 2007

Ya. You can include header file in another file.

//In test.h
#include<stdio.h>

//In test.c
#include "test.h"
int main()
{
printf("Hellon");
}


Here stdio.h header file is included in another header file test.h

The only thing to remember is to  include the file before it is used.

How is structure passing and returning implemented?

Asked By: pbchaudhari | Asked On: Sep 1st, 2007

Answered by: abhimanipal on: Jul 6th, 2009

Here is my code fragement. It shows passing the structure as argument and returning it as well #include <stdio.h>#include <stdlib.h>#include<math.h>#include<string.h>struct abc...

Answered by: baseersd on: Jan 16th, 2008

Here i am trying to i)accept input through GetEmployeeDetails()ii)Print the same details through PrintEmployeeDetails()iii)Modify / Change the details through ModifyEmployeeDetails()iv)Print the modif...

How many types of sortings are there in c? What are they

Asked By: Prakash P | Asked On: Aug 26th, 2007

Answered by: asdf on: Jul 14th, 2011

There are in total 16 types of Sortings....

Answered by: techoverdose on: Mar 3rd, 2011

Basically sorting are of two types only :-

A.Position Based
 1.Selection sort
 2.Radix sort
 3.Bucket sort, etc.

B.Comparison Based
 1.Bubble sort
 2.Quick sort
 3.Merge sort
 4.Binary sort,etc.

What is subscript?

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

Answered by: baseersd on: Sep 18th, 2007

I guess the subscript here in the sense of arrays:

Subscript is the offset of the array.

Say, int array[5];

To access the second element, we use array[1], where 1 is the subscript.
Which mean to point to the location after 1  such element. So it will pass array[0] and it will point the array[1].

Write a C program to check given string is palindrome or not using pointers?

Asked By: Dhanesh | Asked On: Aug 17th, 2007

Answered by: aks3937 on: Aug 24th, 2009

#include<stdio.h>#include<conio.h>void main(){int i,flag=0,k,l,m,n;char str[100];clrscr();printf("enter the string n");scanf("%s",str);l=strlen(str);printf("%d&quo...

Answered by: baseersd on: Jan 7th, 2008

#include<stdio.h>int Ispalindrome(char* str){     int i,len;    len = strlen(str);    for(i = 0; i < len / 2; i++)    { &...

How to find the size of data without using the sizeof() operator?

Asked By: kaliswaranbsc | Asked On: Aug 16th, 2007

Answered by: baseersd on: Sep 18th, 2007

Here is the code for finding the size of data types without using sizeof() #include<stdio.h>#define size_of(data) ( (char *)(&data +1) - (char *)(&data))int main(){    int...

What is the return type of the printf and scanf functions ?1) void2) float3) int4) any

Asked By: ashish1287 | Asked On: Jul 25th, 2007

Int

Answered by: Nikhil Saini on: Aug 14th, 2011

printf return no of char read ..

Code
  1. #include<stdio.h>
  2. #include<string.h>
  3. #include<conio.h>
  4. main()
  5. {
  6. int i;
  7. /*/char str[100];
  8.  
  9. printf("enter string:");
  10. gets(str);
  11. for(i=strlen(str)-1;i>=0;i--)*/
  12. i=printf("");
  13.  printf("%d",i);
  14. }
  15.  
  16.  
  17. output:
  18. 0

Answered by: Tanka on: Jul 13th, 2011

the given piece of code gives no output when a character is provided as input. Why is it so?

 

Code
  1. #include<stdio.h>
  2.  
  3. int main()
  4. {
  5.   char i;              
  6.         printf("
  7. %c
  8. ",scanf("%c",&i));
  9. return 0;
  10.  
  11. }

Can you write and get output for C program without using printf and scanf statements? If yes, how?

Asked By: sampathk | Asked On: Jul 24th, 2007

Answered by: baseersd on: Jul 26th, 2007

You can also use functions like fprintf(),fputs(),gets(),fgets() instead of printf() and scanf().Here is a sample example#include<stdio.h>int main(){  char name[20]=""; ...

Answered by: umar on: Jul 25th, 2007

programming c,we can use getc(),putc(),gets() and puts() function to input get and put.

What is difference between malloc() and calloc() ?

Asked By: vikas | Asked On: Jun 28th, 2007

Answered by: paul.anuj on: Aug 5th, 2008

malloc() and calloc() both are use to allocate memory.malloc takes only one argument that is number of memory bytes, mostly we use sizeof() operator, which allocates the memory of that  number of byt...

Answered by: baseersd on: Sep 18th, 2007

1) malloc() does not initialize the memory allocated. Hence garbage will be present    calloc() initializes the allocated memory with 0.2) malloc() requires 2 arguments in the form of (...

To take a string from the user & then arrange the characters in that string in ascending order like if user enters "babcac" the program should print it as "aabbcc"

Asked By: nadeem | Asked On: Jun 24th, 2007

Answered by: madhwaraj on: Jun 29th, 2008

Using count sort will be more helpful in this case.

Answered by: baseersd on: Jul 19th, 2007

Here is the code for sorting a string in ascending order or alphabetical order#include<stdio.h>int main(){    char str[20]="";    char temp;  &n...

What is difference between function declaration and definition in C programming language

Asked By: poonam | Asked On: Jun 10th, 2007

Answered by: baseersd on: Jul 24th, 2007

Function Declaration means telling the compiler what are the types of arguments that are passed toa function , what type of data type it will return. It is ended with a semicolon (;).Eg : int add(int ...

What would be the output of this program & why#include#define one two#define two oneint main(){ int one=1,two=2; printf("%d%d",one,two); return 0;}

Asked By: himanshujoshi | Asked On: Jun 8th, 2007

Answered by: baseersd on: Jul 19th, 2007

This is the original code....#include#define one two#define two oneint main(){//int one=1,two=2; /*The above statement can be written as the following two statements for a better understanding */int o...

Answered by: neverd on: Jun 11th, 2007

12

Write a program to check if the number is palindrome or not using recursive function.

Asked By: alok kumar | Asked On: Mar 29th, 2007

Answered by: md faiz iqbal faiz on: Jan 15th, 2010

main{ int sum = 0,n,n1,r;  printf(" enter the number to be tested for palimdromen" );  scan("%d",&n);   n1=n;   while(r!=0)   {r=n%...

Answered by: baseersd on: Jul 24th, 2007

Here is the code for palindrome with recursive mechanism#include<stdio.h>int rev=0; //Global Variableint REV(int num){if(num>0){ rev=(rev*10)+ (num %10); REV(num / 10); //calli...

Q. Write a function(efficient) to find the next prime number after a given number ?

Asked By: rameshwar83 | Asked On: Feb 13th, 2007

Answered by: sarathi trichy on: Oct 24th, 2007

#include<stdio.h>#include<conio.h>void main(){ int a,i;clrscr();printf( " enter the number");scanf("%d",&a);for(i=a;i<a+1000;i++){if(i==1||i==2||i==3||i==5|...

Answered by: baseersd on: Jul 24th, 2007

#include<stdio.h>main(){int i,j,count,num;printf("nEnter the number");scanf("%d",&num);for(i=num+1;1;i++){ for(j=2,count=0;j<=i;j++) {    ...

Which one saves execution time and why i++, ++i, i=i+1 , i+=1.

Asked By: rameshwar83 | Asked On: Feb 12th, 2007

Answered by: jbode on: Feb 1st, 2011

The only way to know for sure is to code up each version and measure their performance, or examine the generated machine code.  Never blindly assume that any one form is going to be faster than t...

Answered by: rajkumar_ks on: Jun 25th, 2009

++i executes faster, since both i++ and ++i takes one cycle. i++ creates a temporary variable and then put the incremented value in it but ++i directly increments the value.

Write a program to count the occurrence of following C keywords in a file and calculate the sum? 1.Int 2.Char 3.Static 4.Struct 5.Union 6.Return

Asked By: rafiuddin | Asked On: Jan 29th, 2007

Answered by: baseersd on: Jul 24th, 2007

#include<stdio.h>int main(){char keywords[6][10]={"int","char","static","struct","union","return"};int count[7]={0};FILE *fp;char str[...

I want a C program for : if the list of students’ information is represented by a linked list, write a program which implements deletion of the node with given student id. The student information which...

Asked By: souji1425 | Asked On: Jul 12th, 2006

Answered by: baseersd on: Jul 23rd, 2007

#includestruct node{int id;char name[25];struct node *next;       };typedef struct node* NODE;NODE CreateNode(){ NODE new_node; new_node=(NODE)malloc(sizeof(struct node)); if(new_node == NULL) {  prin...

I want a C program to rearrange a linked list so that nodes with even numbers as their information come first. Input:the input consists of the information in each node of the linked list. Output:the program...

Asked By: souji1425 | Asked On: Jul 12th, 2006

Answered by: baseersd on: Jan 21st, 2008

#include<stdio.h>typedef struct _node NODE;struct _node{ int num; NODE *next;       };NODE* New_Node(NODE *Head,int num){ NODE *temp,*Curr; if(H...

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

How are pointer variables initialized? 

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

Pointer variable are initialized by one of the following two waysØ                  static memory allocation Ø                  dynamic...

Answered by: baseersd on: Mar 19th, 2008

Hope this may be the possible answer.#include<stdio.h>#define MAX 5int main(){    int p[] = {1,2,3,4,5};//Static initialization    int *q = NULL;    ...

Interview Question

 Ask Interview Question?

 

Career Counselling

 Have Career Question?

 Ask Chandra

 Ask Only Career questions.

Follow us: