C

C Subjective Questions And Answers
What are the characteristics of arrays in C?
some main characteristics of arrays are given below:

1.all entry in array should have same data type.
2.tables can store values of difference datatypes.
More interview questions and answers

What is C language?

Programming language

What is the output of printf(\"%d\")?

0

What is the difference between \"calloc(...)\" and \"malloc(...)\"?

Some important distance between calloc and malloc are given below:
 
malloc:
 
malloc takes only the \"size\" of the memory block to be allocated as input parameter.
malloc allocates memory as a single contiguous block.
if  a single contiguous block cannot be allocated then malloc would fail.

calloc:

calloc takes two parameters: the number of memory blocks and the size of each block of memory
calloc allocates memory which may/may not be contiguous.
all the memory blocks are initialized to 0.
it follows from point 2 that, calloc will not fail if memory can beallocated in non-contiguous blocks when a single contiguous blockcannot be allocated.

What is the difference between \"printf(...)\" and \"sprintf(...)\"?

the printf() function is supposed to print the output to stdout.In sprintf() function we store the formatted o/p on a string buffer.

How to reduce a final size of executable?

Do not include unnecessary header files and 
Do not link with unneccesary object files.

  

Can you tell me how to check whether a linked list is circular?

First you have to Create two pointers, each set to the start of the list. And Update each as below:

while (pointer1) {
    pointer1 = pointer1->next;
    pointer2 = pointer2->next; 
if (pointer2)   
    pointer2=pointer2->next;
if (pointer1 == pointer2) {
    print (\"circular\n\");
}
}

What is the difference between String and Array?

Main difference between String and Arrays are:

 A string is a specific kind of an array with a well-known  convention to determine its length where as An array is an array of anything.

In C, a string is just an array of characters (type char)and always ends with a NULL character. The �value� of an array is the same as the address of (or a pointer to) the
first element; so, frequently, a C string and a pointer to char are used to mean the same thing.
An array can be any length. If it�s passed to a function, there�s no way the function can tell how long the array is supposed to be, unless some convention is used. The convention for strings is NULL termination; the last character is an ASCII NULL character.
 

What is a modulus operator?

it gives reminder of any division operation

What are the restrictions of a modulus operator?

The modulus operator is denoted in c by symbol %.

we have two integer values x and y and then the operation x % y called as x modulus y gives the result as (x- (x / y) * y).

Say if x=18 and y =5 the x % y gives value as (18- (18 / 5) * 5) which gives (18-15) which results in 3 in other words the remainder of the division operation.

But there is a restriction in C language while using the modulus operator. There are two types of numerical data types namely integers, floats, double. But modulus operator can operator only on integers and cannot operate on floats or double. If anyone tries to use the modulus operator on floats then the compiler would display error message as �Illegal use of Floating Point�.

Which one is faster n++ or n+1?Why??

The expression n++ requires a single machine instruction. n+1 requires more instructions to carry out this operation.

What is equivalent expression for x%8?

while(x>8)
{
   x=x-8;
}
printf("%d",x);
 
Get the remainder

Which expression always return true?and Which always return false?

Expression are given below;
  
if (a=0) always return false.
if (a=1) always return true.


What is Storage class ?

There are four type of storage class in C:

1.static
2.auto
3.register
4.extern

what are storage variable ?

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

What are the advantages of auto variables?

Some main advantages of auto variables are given below:

1.we can use the same auto variable name in different blocks.
2.No side effect by changing the values in the blocks.
3.It used memory economically.
4.Because of local scope auto variables have inherent protection. 

What is auto variables?

by default  variables are auto.as we know that variable changes its character according to the strage class .  

Diffenentiate between an internal static and external static variable?

Some main difference between internal static and external static are given below:

We declare the internal static variable inside a block with static storage class. External static variable is declared outside all the blocks in a file.
In internal static variable has persistent storage,no linkage and block scope, where as in external static variable has permanent storage,internal linkage and file scope.

What are advantages and disadvantages of external storage class?

Some main advantages and disadvantages of external storage class are given below:

advantage:

1.In Persistent storage of a variable retains the updated value.
2.The value is globally available.
 
Disadvantage:

1. Even we does not need the variable the storage for an external variable exists.
2.Side effect may be produce unexpected output.
3.We can not modify the program easily.


What are the characteristics of arrays in C?

some main characteristics of arrays are given below:

1.all entry in array should have same data type.
2.tables can store values of difference datatypes.

When does the compiler not implicitly generate the address of the first element of an array?

When array name appears in an expression such as:

1.array as an operand of the sizeof operator.
2.array as an operand of & operator.
3.array as a string literal initializer for a character array.
Then the compiler not implicitly generate the address of the first element of an array.

What is modular programming?

It is a programming technique that cut the program function into small modules.Each module has one function that have all codes and variables needed to execute them.
  Using modular programming we can easily found out the bugs from very large program.Object-oriented programming languages, such as Smalltalk and HyperTalk,incorporate modular programming principles. 

What is a function and built-in function?

function is that when large program is divided into sub programs.where as each one done one or more actions to be performed for a large program. Those subprograms are called functions.they support only static and extern storage classes.  

Built-in functions(Library function) that which are predefined and supplied with the compiler called as built-in functions.

What is an argument ? differentiate between formal arguments and actual arguments?

Using  argument we can pass the data from calling function to the called function. 

Arguments available in the funtion definition are called formal arguments. Can be preceded by their own data types.

We use Actual arguments in the function call.

What is the purpose of main( ) function?

Main function is to be called when the program getting started.
1.It is the first started function.
2.Returns integer value. 
3.Recursive call is allowed for main() also.
4.it is user-defined function
5.It has two arguments: 
  5.1)argument count  
  5.2) argument vector(strings passed)
6.We can use any user defined name as parameters for main(),behalf of argc and argv.

What is a method?

A Method is a programmed procedure. It is defined as part of a class also included in any object of that class. Class can have more than one methods.  It can be re-used in multiple objects.

What are the advantages of the functions?

Some main advantages of the functions are given below:
 
1.It makes Debugging easier.
2.Using this we can easily understand the programs logic.
3.It makes testing easier.
4.It makes recursive calls possible.
5.These are helpful in generating the programs.   
 

What is a pointer variable?

 A pointer variable is used to contain the address of another variable in the memory.

What is a pointer ?

Pointers are often thought to be the most difficult aspect of C.A pointer is a variable that points at, or refers to, another variable. That is, if we have a pointer variable of type ``pointer to int,`` it might point to the int variable i

What is a pointer value and address?

It is a data object,it refers to a memory location.we numbered every memory locaion  in the memory.

Numbers that we attached to a memory location is called the address of the location.

Are pointers integers?

A pointer is an address not an integer. It should be a +ve number.

How are pointer variables initialized?

 We can initialize the Pointer variables by using one of the two ways which are given below:

1.Static memory allocation
2.Dynamic memory allocation

What is static memory allocation and dynamic memory allocation?

Information regarding static men\mory allaocaion and dynamic memory allocation are given below:

Static memory allocation: 

The compiler allocates the required memory space for a declared variable.Using the address of operator,the reserved address is obtained and assigned to a pointer variable.most of the declared variable have static memory,this way is called as static memory allocation.
In tis memory is assign during compile time.

Dynamic memory allocation: 

For getting memory dynamically It uses functions such as malloc( ) or calloc( ).the values returned by these functions are assingned to pointer variables,This way is called as dynamic memory allocation.
In this memory is assined during run time.

What is the purpose of realloc( )?

Realloc(ptr,n) function uses two arguments.

The first argument ptr is a pointer to a block of memory for which the size is to be altered.

The second argument n specifies the new size.The size may be increased or decreased.

Difference between arrays and pointers?

Arrays automatically allocate space with fixed in size and location,but in pointers above are dynamic.

array is refered directly to the elements.
but pointers refers to address of the elements. 

What is difference between static and global static variable?

Main difference between static and global static variables are given below:

In context of memory it allocated to static variables only once. 

Static global variable has scope only in the file in which they are declared. outside the file it can not be accessed. but its value remains intact if code is running in some other file 

What are the packages in c?

How to use floodfill() function ?

The main issue of making floodfill function is that it connect the connected pixels of an entire area with same color.It also called Bucket tool in all programming languages.
  Keep one thing in mind FloodFill function has only compatibility with 16 bits operating system.You should use the ExtFloodFill function with FLOODFILLBORDER.
Syntax:
BOOL FloodFill(
     HDC hdc,          // handle to DC
     int nXStart,      // starting x-coordinate
     int nYStart,      // starting y-coordinate
     COLORREF crFill   // fill color
);
  
Where:
hdc -> Handle to a device context.
nXStart->Starting X-Coordinate.
nYStart->Starting Y-Coordinate.
crFill->Then area to be filled

What is the use of kbhit?

kbhit() defined in the header conio.h checks to see if a keystroke is currently available.
The available keystroke can be retrieved with getch() of getche();
It returns a non-zero value when there is a keystroke else it returns zero.

Write a program with out using main() function?

No,we can write a program with out main function, this function is the main function which usually help OS to kill the process that has executed.   

Constant volatile variable declaration is possible or not? if give any one example and reason.

yes, constant variable declaration is possible. Constants can be defined by placing the keyword const in front of any variable declaration. If the keyword volatile is placed after const, then this allows external routines to modify the variable. 

Example: An input-only buffer for an external device could be declared as const volatile to make sure the compiler knows that the variable should not be changed and that its value may be altered by processes other than the current program.

How to print 1 to 100 without using any conditional loop?

There are 2 ways i have given you. Using these you can solve this problem.

1.Using Recursion:

DisplayInfo(Int num = 1)
{
   Printf("%d ", num);
   if(num == 100)
   return;
   else
   DisplayInfo(++num);
} 

2.

#include
#include
void main()
{
   int n=1;
   clrscr();
   SHOW:
   if(n>100)
{
}
   else
{
   printf("%d ",n);
   n+=2;
   goto SHOW;
}
getch();
} 

How pointer variables are initialized ?

There are 2 main ways to initialize pointer vaiables.These are:

1.Static Memory Allocation(SMA)
2.Dynamic Memory Allocation(DMA)

Some initialization of pointer variables are given below:

1.As Datatype:
  We can initialize pointer variables as   datatype *VariableName(Declaration)
e.g. int *ptr,i;

It can be initialized as
ptr=&i;

2.We can also initialized pointer as:
int i;
int *ptr;
ptr= null;
ptr=&i;

3.Below I have given a eg for you. This example defines weekdays as an array of pointers to string constants. 

static char *weekdays[ ] =
            {
              "Sun", "Mon", "Tue",  "Wed",
              "Thu", "Fri", "Sat"
            };
            




Does mentioning the array name gives the base address in all the integers?

Explain one method to process an entire string as one unit?

using gets

How can we check whether the contents of two structure variables are same or not?

Here below I given a fully tested program which solve your problem.

In this i given two structures named str1 and str2.
Program return 1 when they have been matched other wise return 0. You can run this program in VC++.

#include 
#include 
#include 

compare(i,j,l)
char *i, *j;
int l;
{
   int n;
   for (n=0; n");
   scanf("%d %s %lf", &n,s,&d );
   str1.a=n; 
   strcpy(str1.s,s);
   str1.d=d;
   printf("Enter str2 values (int, char 4, double)-->");
   scanf("%d %s %lf", &n,s,&d );
   str2.a=n;
   strcpy(str2.s,s);
   str2.d=d;
   strs=compare ((char *)&str1, (char *)&str2, sizeof(struct str));
   printf("strs = %d\n", strs);
}

How can we read/write structures from/to data files?

There 2 function given in C++. They are fread() & fwrite(). Using them we can read & write structures
from/to data files respectively.

Basic representation:
fread(&structure, sizeof structure,1,fp);

 fread function recieves a pointer to structure and reads the image(memory) of the
structure as a stream of bytes. Sizeof gives the bytes which was occupied by structure.

fwrite(&structure, sizeof structure,1,fp);

 fwrite function recieves a pointer to structure and writes the image(memory) of the
structure as a stream of bytes. Sizeof gives the bytes which was occupied by structure.

What are bit fields?

Bit Field is used to make packed of data in a structure.Using bit fields we can communicate Disk drives and OS at alow level.Disk drives have many registers, if want to packed togather in only one register we have to use bit fields.

 

 

 

If we want that any wildcard characters in the command line argument should be approxiemately expanded , are we required to make any special provision?if yes, which?

What is the use of bit fields in a structure declaration?

In C we store the integer members into the memory space.This memory space saving structures is named as bit fields and declared width in bits  explicitly. 

The Representation of declaring a bit field is given below: 

>>-specifier_type-+---------+--:-constt_expression-;-><
                  'declarator'
  A bit field declaration may not use type qualifiers,constt or volatile.

In C, C99 standard requires the allowable data types for bit field to include qualified and unqualified _Boolean, signed integer and unsigned integer. In addition, this supports the following types.

    # int
    # long, signed long, unsigned long
    # short, signed short, unsigned short
    # char, signed char, unsigned char
    # long long, signed long long, unsigned long long 

By default  bit field(integer type) is unsigned.

What is object file?

Object file is used to store the instruction given by machine language and Data. Data should be same as programer used to make an executable program.

Object file are of 3 types.Those are given below:
1.An executable file
2.A relocatable file 
3.A shared object file
 
1.An executable file: It has program that does not create problem at execution time. It also display the image of process.

2.A relocatable file: It has Data with their code those does not create link with other object file for make an executable file.

3.A shared object: It store data and their code those suit for link in 2 contexts.
 
3.1The shared object file with other relocatable and shared object files to create another object file processed by link editor.
3.2 Using dynamic link we combine with an executable file, Other shared objects is used to make image of process.

How can you access object file?

What do the functions atoi(),itoa()and gctv()do?

In basic term we can say that atoi() is used to change string to integer ,itoa() is used to change integer to string and gctv() is used to change double to sting.Huge knowledge about those are given below:

atoi()is used to change strings("65"or"87vivek") into integers, They gives 65 and 87 respectivey.
first character isn't a no or -ve, Then atoi returns 0.
For atoi it is mandatry one char * argmt and returns int (not a float!).

itoa()is used to change integer(65)into string("C").

How would you qsort() function to sort an array of structures?

Using qsort() function we sort an array of structure in c/c++ standard.For Using this function we have to include stdlib.h library.
Representation: basic reoresentaion of qsort() function is,

void qsort(void *Base, size noe , size width, int (*compar)(constt void *, constt void *));

where: 
Base-> Pointer indicates beginning of array.  
noe-> Number of Elements.
Width-> Size of Element.
Compare-> Does comparison and returns +ve or -ve integer.It is a callback function (pointer to function). 

Example:
This Examples uses structs_sort() function.It is use to compare struct_cmp_product_price() and struct_cmp_product() as compar callbacks.struct_array is used to print structure of array.

void structs_sort(void)
{
    struct st_eq structs[] = {{"Computer",24000.0f}, {"Laptop", 40000.0f}, 
                              {"Inverter", 10000.0f}, {"A.C.", 20000.0f}, 
                              {"Refrigerator", 7000.0f}, {"Mobile", 15000.0f }};
 
    size structs_len = sizeof(structs) / sizeof(struct st_eq);
 
    puts("*** Struct sorting (price)...");
 
    /* original struct array */
    print_struct_array(structs, structs_len);
 
    /* sort array using qsort functions */
    qsort(structs, structs_len, sizeof(struct st_ex), struct_cmp_product_price);
 
    /* print sorted struct array */
    print_struct_array(structs, structs_len);
 
    puts("*** Struct sorting (product)...");
 
    /* resort using other comparision function */ 
    qsort(structs, structs_len, sizeof(struct st_eq), struct_cmp_product);    
 
    /* print sorted struct array */
    print_struct_array(structs, structs_len);
}
 
 
/* MAIN program */
int main()
{
    /* run all example functions */
    sort_integers();
    sort_cstrings();
    sort_structs();
    return 0;
}

How would you use qsort() function to sort the name stored in an array of pointers to string?

How would you use bsearch()function to search a name stored in array of pointers to string?

bsearch, It is a library function.Using this we done data entry in array. Ther is mandatry in binary search your must sorted in ascending order.And do compare two datas.For using this function we have to include stdlib.h library function.

Syntax:

void *bsearch(void *key, void *base, size num, size width,
int (*cmp)(void *emt1, void *emt2));

where;
emt->Element.

Some steps that we have to follow when we using 
bsearch.

1. It is passed pointers to two data items
2. It returns a type int as follows:
   2.1) <0 Element 1 is less than element 2.
   2.2) 0 Element 1 is equal to element 2.
   2.3) > 0 Element 1 is greater than element 2. 
example:

#include 
#include 
#include 
#define TABSIZE    1000

struct node { /* These are stored in the table. */
   char *string;
   int length;
};
struct node table[TABSIZE];/*Table to be search*/
    .
    .
    .
{
    struct node *node_ptr, node;
    /* Routine to compare 2 nodes. */
    int node_compare(const void *, const void *);
    char str_space[20];   /* Space to read string into. */
    .
    .
    .
  node.string = str_space;
  while (scanf("%s", node.string) != EOF) {
         node_ptr = (struct node *)bsearch((void *)(&node),(void *)table, TABSIZE,sizeof(struct node), node_compare);
  if (node_ptr != NULL) 
  {
     (void)printf("string = %20s, length = %d\n",
             node_ptr->string, node_ptr->length);
  } 
  else 
  {
     (void)printf("not found: %s\n", node.string);
  }
}
}
/*
    This routine compare two nodes based on an
    alphabetical ordering of the string field.
*/
int node_compare(const void *node1, const void *node2)
{
   return strcoll(((const struct node *)node1)->string,((const struct node *)node2)->string);
}

How to add 2 numbers without + sign?

I have given you some examples.Which add 2 numbers with using + sign.
 
Using recursion:

#include 

int add(int m, int n)
{
  if (!m) 
  return n;
  else
  return add((m & n) << 1, m ^ n);
}
int main()
{
   int m,n;
   printf("Enter the 2 numbers: \n");
   scanf("%d",&m); 
   scanf("%d",&n);
   printf("Addition is: %d",add(m,n));
}
m ^ n is mandatry in addition of bits, "(a & b) << 1" is the overflow. 

Using Binary operator:
1 = 001
2 = 010
add(001, 010) => a -> 001, b-> 010
=011

Write a program for n lines 1 2 3 4 5 16 17 18 19 6 15 24 25 30 7 14 23 22 21 8 13 12 11 10 9

How to decide even and odd values without decision making loops?

How i can run *.bat or *.cmd file by using system function in c ?

Why does a linker error occurs for the segment: main() { extern int i; i=20; printf("%d",sizeof(i)); }

In the given example extern int i means we only declare the i.It means compiler think that 'i' only used but does not know which memory is allocated to i,and in next line we call the i but because of missing of memory space it gives a linkage error.

Can there be a mouse click and drag function used together to rotate a circle in c

Can there be a mouse click and drag function used in c?

What is the difference between compile time error and run time error?

Some main differences between compiler time error and run time error are given below:

1.Compile time error are semantic and syntax    error. Where Run time error are memory allocation error e.g. segmentation fault.

2.Compile time errors comes because of improper Syntax.Where In java Run time Errors are considered as Exceptions.Run time errors are logical errors.

3.Compile time errors are handled by compiler. where Run time errors are handled by programmers.

How to connect a database (MS Access) to Borland C?

Waht is difference between strdup and strcpy?

Some main difference b/w strdup and strcpy are given below:

1.strdup: copy a string to a location that will be created by the function. The function will allocate space, make sure that your string will fit there and copy the string. Will return a pointer to the created area. 
strdup call malloc to allocate storage. Therefor you have to call free when you are not using it.
Syntax:

char name[] = "Welcome";
char* copy = 0;
copy = strdup(name);

2.strcpy:copy a string to a location YOU created (you create the location, make sure that the source string will have enough room there and afterwards use strcpy to copy)
strcpy copy from source to destination without doing overflow checking.
Syntax:

char name[255];
strcpy(name, "Welcome");

What are bit fields? What is the use of bit fields in a structure declaration?

When ever it is necessary to pack several objects into single machine word ,one common use is a set of single bit flags in application like compiler symbol tables.It is called bit fields. A bit field is a set of adjacent bits with a single implementation.
Syntax:

struct {
     unsugned int is_keyword : 1;
     unsigned is_extern :1;
     unsigned is_static : 1 ;
       } flags ;
flags.is_extern = flags.is_static = 1 ; 

Are the variables argc and argv are local to main()?

Yes,argc and argv variables are local to main().Because write any thing b/w parenthesis is work as local to that method.

What are enumerations?

Enumeration is a kind of type.It is used to hold the group of constt values that are given by programmer.After defining we can use it like integer type.e.g.

enum off,on;
 
Here,off and on are 2 integer constants.These are called enumerators.By default value assign to enumurator are off. 

Write down the equivalent pointer expression for reffering the same element a[i][j][k][l]?

What is the use of typedef?

Which mistakes are called as token error?

What is the function of % using in formatted string.

What is the difference between #include and #include ?file?

In C we can include file in program using 2 type:
1.#include
2.#include?file?

1.#include:In this which file we want to include surrouded by angled brakets(< >).In this method preprocessor directory search the file in the predefined default location.For instance,we have given include variable
INCLUDE=C:COMPILERINCLUDE;S:SOURCEHEADERS;
In this compiler first checks the C:COMPILERINCLUDE directory for given file.When there it is not found compiler checked the S:SOURCEHEADERS directory.If file is not found there also than it checked the current directory.

#include method is used to include STANDARDHEADERS, like:stdio.h,stdlib.h. 

2.#include?file?:In this which file we want to include surrouded by quotation marks(" ").In this method preprocessor directory search the file in the current location.For instance,we have given include variable
INCLUDE=C:COMPILERINCLUDE;S:SOURCEHEADERS;
In this compiler first checks the current directory.If there it is not found than it checks
C:COMPILERINCLUDE directory for given file.When there it is not found compiler,than checked the S:SOURCEHEADERS directory.

#include?file?method is used to include NON-STANDARDHEADERS.These are those header files that created by programmers for use . 
                    

How to print the names of employees or students in alphabetical order using C programming?

When should we not use Quick sort as a sorting technique?

How should i rate on the basis of the basis of the scenario the insertion sort , bubble sort , Quick Sort?

What are comment line arguments in C programing?

What is the difference between null array and an empty array?

I will give you some important difference b/n null & empty array.

1.Due to difference in memory allocation, Null array has not allocated memory spaces.Where as Empty array has memory allocated spaces.
2.In an Null array object are not assign to the variables, Where as in an empty array object are assign to the variables.
  Suppose, It we want to add some values in both array than in case of Null array first we have to assign the object to the variables after that we have to add values.Where as in case of Empty array we have to only add the values.
3.When we declare int* arr[] as globel it has only null that means it is an null array.
When array has 0 elements is called empty array.

 

How to write a program to print its own source code?

I will given you 2 examples those program print its own source code.
In C:

#include 
main()
{
   FILE *fd;
   int c;
   fd= fopen("./file.c","r");
   while ( (c=fgetc(fd)) != EOF)
   {
      printf("%c", c);
   }
   fclose(fd);
} 

In C++:

#include
#include
#include
#include
#include
void main()
{
   char ch;
   clrscr();
   fstream fout;
   fout.open("own_source_code.c",ios::in);
   if(!fout)
   {
      printf("\n can't open");
      exit(0);
   }
      while(ch!=EOF)
      {
         ch=fout.get();
         cout<

Difference between malloc and calloc?

Some main and important difference b/n malloc and calloc are given below:

malloc is use for memory allocation and initialize garbage values. where as calloc is same as malloc but it initialize 0 value.
example:

// This allocats 200 ints, it doesn't initialize the memory:
int *m = malloc(200*sizeof(int));

// This, too, allocates 200 ints, but initializes the memory
// to zero:
int *c = calloc(200,sizeof(int));
 

How much memory does a static variable takes?

Memory allocated to static variable is not depends on static keyword. only depends on data type.So, it is called an static specifier.It only occupies the values of int,char,float etc.static keyword does not required any memory.
example:

static int p;
static char q;
static float r;
static short int s;
printf(" %d %d %d %d ", sizeof(p), sizeof(q),  sizeof(r), sizeof(s));

o/p: 4 1 4 2 (In case of 32 bit compiler)

In case of Dos static occupies 2 bytes for integer.

What are the uses of pointers in c and c++ language?

Can we execute printf statement without using semicolan?

Yes,We can execute printf statement without using semicolan. When we write printf inside the if,for,while,do while etc it gives output.
Example:
void main()
{
   if(printf("R4R Welcomes you!"))
   {
      /*statements*/
   }
getch();
}

void main()
{
   while(printf("Welcome"))
   {
      /*statements*/
   }
getch();
} 

int main()
{
   int flag = 1;
   int test = 10;
   if (printf("%d",test))
   flag = 0;
   else
   flag = 1;
   return 0;
}
o/p will be 10 and after that when we check the value of flag, it shows 0.return type of printf is int.

How to perform addition,subtraction of 2 numbers without using addition and subtraction operators?

How to write a program in c to print its own code?

#include
#include
void main()
{
int x,i,c;
char msg[20];
printf("enter the massage");
scanf("%s",msg);
printf("enter the number");
scanf("%d",&x);
for(i=1;i

What is the function of c?

main() function is essential in c programming language.It is function which controls other function those write with in c.These functions are user defined function.C program starts execution from main() function & ends with null statement.
main function has three parameters:
1.Environment vector
2.Argument counter 
3.Argument vector

Function those we write in c program performs one or many specific tasks.main function call those function and given authority of execution to those function. main function call those function first passes execution controls to them.Than execution becomes started.when called function is executed than it returned the controlled to the main function.   

Is C is platform dependent or independent?how and why?

 Major issue behind designing C language is that it is a small,portable programming language. It is used to implement an operating system.In past time C is a powerful tool for writing all types of program and has mechanism to achieve all most programming goals.So, we can say that C is platform dependent. 

how to print this : 1 11 121 1331 14641 using for loop

void main()
{
int a[10][10],i,j;
for(i=0;i<10;++i)
  {

   printf("\n");
   for(j=0;j<=i;++j)
   {
     if(j==0 || i==j)
      a[i][j]=1;
      else
       a[i][j]=a[i-1][j-1]+a[i-1][j];
       printf("%4d",a[i][j]);

   }
  }



}

how to switch the values of two variable without using third variable?

I have given a example which switch the values of two variables without using third variable.   

#include
void main()
{
  int val1,val2;
  val1=5;
  val2=6;
  /* now adding val2 to val1 we have */;
  val1=val2+val1;
  val2=val1-val2; 
/* now here val2 will get value of val1 */;
  val1=val1-val2 
/*this will give val1 value of val2 */;
} 

#include #include void main() { printf("%d"); getch(); }

How many nodes do a complete full binary tree with 10 leaves have?

how to print this : 1 11 121 1331 14641 using for loop?

for (int i = 0; i <= 4; i++) 
{
print(Math.pow(11, i) + \" \");

 }

What is Difference Between C/C++?

Define the generic programming?

What are the types of file pointers?and whats the uses of the file pointers?

How to reverse a string using a recursive function, with swapping?

I have given you a solution. That's solve out this problem:

#include
#include
char m1[50];  //GLOABAL VARIABLE.
void reverse(int);
void main()
{
   int count=0;
   printf("Enter the given string :");
   scanf("%s",m1);
   for(int i=0;m1[i]!='\0';i++)
   count++;
   reverse(count);
   getch();
}

void reverse(int count1)
{
   char temp;
   static int i=0;
   if(i!=count)
   {
      temp=a1[i];
      m1[i]=m1[count1-1];
      m1[count1-1]=temp;
      i++;
      reverse(--count1);
   }
   else
      printf("\nThe reversed string is :%s",m1);
} 

I want to have a program to read a string and print the frequency of each character and it should work in turbo c

Our desired program is that,

#include
#include 
void main()
{
   int i[26],m,l,n;
   char str[180];
   clrscr();
   for(m=0;m<26;m++)
   i[m]=0;
   printf("Enter a string: \n");
   gets(str);
   l=strlen(str);
   for(m=0;m

Write a function for strtok()?

strtok() function is used to cutting the string into slice.Using this we include string.h header file.

How to use:

#include 

char *token;
char *line = "LINE TO BE SEPARATED";
char *search = " ";

/* Token will point to "LINE". */
token = strtok(line, search);

/* Token will point to "TO". */
token = strtok(NULL, search);

Example:

#include
int main()
{
   char *t;
   char s[40]="welcome at r4r.";
   p=strtok(s," ");
   printf("%s",t);
   do
   {
     t=strtok('\0',", ");
     if(t)
     printf("|%s",t);
   }while(t);
   printf("\n");
}

O/P
welcome|at|r4r.

What is the difference between char *a and char a[]?

Using char*a there is no problem to edit local data.Example: Array is a local data.
Where as char a[] is a local pointer to global, static(constt) data.You can not modify the constt data.

char *s = "vivek";
+-----+        +---+---+---+---+---+---+------+
| s: | *======> | v | i | v | e | k |'\0'|
+-----+        +---+---+---+---+---+---+------+
Pointer              Anonymous array

char s[] = "vivek";
+----+----+----+----+-----+------+
s: | v | i | v | e | k |'\0' |
+----+----+----+----+-----+------+
s[0] s[1] s[2] s[3] s[4] s[5] 



What is a memory leak?

Memory leak is that when memory is allocated but its not released because of an application consume memory reducing the available memory for other applications and causing the system to page virtual memory to the hard drive showing the application or crashing the application. When the computer memory resource limits are reached.

example:
Suppose, We have allocated 10 bytes to each MemoryArea and NewMemArea.

Now,If we execute the statement which is given below:
MemoryArea = NewMemArea

In this programmer has assigned the MemoryArea pointer to the NewMemArea pointer.So that,the memory location to which MemoryArea was pointing to earlier becomes an orphan. It cannot be freed, as there is no reference to this location. This will result in a memory leak of 10 bytes.

Before assigning the pointers, make sure memory locations are not becoming orphaned.

What is difference b/w huge & far & near pointer?

In old days when Intel introduce hybrid 8bit/16bit family of processors named iAPX 86.(8086 etc)
 Using this 8bit code changed to the 16bit architecture by 16bit pointers operating with in overlapping segments.

A huge pointer is 16:16(Where additional code negotiated segment boundaries).
A far pointer is 16:16(Where we can only offset with in the same segment).
A near pointer is 16bits.

What is the difference between system call and library function?

The key difference b/n system call & library function are given below:

1.System calls are given by system and executed in the system kernel. Than they are called non-portable calls  where as library function include ANSI C standard library.So, they are portable.
2.System calls are entry point into the kernel.So, they are not linked with the program.
Where as library functions are linked with the program.
3.System calls are given by system,Where as library functions are given by programmer.
4.In system calls,time overhead in calling the system call since a transition has to take place between user mode and kernel mode,Where as time overhead is not required in library function call. 
5.In C, We use open() to open a file is a system call,Where as use fopen() to open a file is a library function.

Whar is the Auto storage class in C ?

How to convert an char array to decimal array?

Using this program you can convert an char array to decimal array:

#include
int main()
{
   char st[40],*s;
   char c,speak;
   do
   {
     s=st;
     printf("Enter the string:");
     fgets(st,40,stdin);
     do
     {
        printf("%d ",*s++);
     }while(*s);
printf("\nDo u want to enter other string(y/n)");
speak=getchar();
if(speak=='n')
break;
}while((c=getchar())!='n');
printf("\n");
}

  

How to fill a rectangle using window scrolling in C?

Explain about storage of union elements.

The key point about storage of union elements is that Union elements are use to share common memory space.

How to differentiate while and do while statement?

The key difference b/n while and do while statement is that:

1.In while first checked the condition after that loop is executed. Where as in do while loop is executed at least one time when ever condition is true or false.

2.Syntax for while loop:
    
while (condition checked)
{
  //block of code
}

Syntax for do while loop:
do
{
   //block of code
} while (condition checked);

3.Example:
Use of while:
This program counts from 1 to 100.
#include 
int main(void)
{
    int count = 1;
    while (count <= 100)
    {
       printf("%d\n",count);
       count += 1; // statement
    }
return 0;
}
Use of do while:
include 
int main(void)
{
    int val, r_digit;
    printf(�Enter a number to be reversed.\n�);
    scanf(�%d�, &val);
    do
    {
       r_digit = val % 10;
       printf(�%d�, r_digit);
       val = val / 10;
    } while (val != 0);
printf(�\n�);
return 0;
}

How to convert a string into integer?

I have given you a example. That's solve your problem.

int s(char str[])
{
    int n=0,m;
    for(int m=0;str[m]>='0' && str[m]<='9';m++)
    n=10*n+(str[m]-'0');
    if(m

How to print our name without using semicolon in c?

I have given you a code that definitely solve your problem.

#include
int main()
{
  int n;
  if(printf("vivek"))
  {
     n=1;
  }
getch();
} 

How to print value of integers into words?

Below i a program to solve given problem:

#include
int main()
{
   int n;
   clrscr();
   printf("\nEnter the integer number::");
   scanf("%d",&n);
   switch(n)
   {
      case:1
      printf("\nOne");
      break;
      case:2
      printf("\nTwo");
      break;
      case:3
      printf("\nThree");
      break;
      case:4
      printf("\nFour");
      break;
      case:5
      printf("\nFive");
      break;
      case:6
      printf("\nSix");
      break;
      case:7
      printf("\nSeven");
      break;
      case:8
      printf("\nEight");
      break;
      case:9
      printf("\nNine");
      break;
      default:
      printf("\nSorry");
}
getch();
} 

What will be the output of x++ + ++x?

let, x = 1. Than answer will be. 
main()
{
   int x=1,y;
   y = x++ + ++x;
   printf("/n%d",y);
}

Ans:  y = 3

  

what are header files?Can i run program without using header file?

Basically header files are the library functions.Header files have definitions of functions.These are required to execute the specific operation of function.we write header file with .h extension.Generally these are pre-defined fuctions,But we can also generate
our own header file.
Example:
stdio.h header file is use to perform function like prinf and scanf.
conio.h header file is use to perform function like clrscr and getch.
 
 

What is macro?

Macros are the fragment of code.That are used to given a name.When we want to used thew name it is being replaced by content of macros.we can differentiate macros in terms of what they look like & when they are used.Macros are of two types:
1.Object-like macros.
2.Function-like macros.
    When we used Object-like macros It resembles data objects.Where as when we using function-like macros it resembles function calls.

How multiplication take place upto 200 digits?

I have given you a program that solve your problem.

#include
#include
#include
#include
char * mul(char *, char);
char * add(char *, char *);
void main()
{
   char *no1=(char * )malloc(100);
   char *no2=(char *)malloc(100);
   char *u="0";
   char *v;
   int i=0,j=0,t=0,l=0;
   clrscr();
   printf("\n Enter the large no ");
   gets(no1);
   printf("\n Enter the second no ");
   gets(no2);
   while(l

How to differentiate i++* and *++i?

i++* is false representation.
*++i->First it increment the value of i,after that is points the value to i.
 

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

Key difference b/n getch() and getchar() are given below:
getch() read the key hits without waiting you to press enter.Where as getchar() does not read key hits and wait till you press enter.

Write a program crashed before reaching main? If happen, how?

In C,Using startup functions global variables are initialized before execution of main function.When any errors come in global memories than It can crashed before reaching the main.

int foo()
 {
    // It comes here before main is invoked
    //Hence a crash happening in this function  
obviously ,will happen before main is called
    //  s simple crash :)
    swprintf(NULL,L"%s",L"crash");
    return 1;
}
int i = foo();
int _tmain(int argc, _TCHAR* argv[])
{
   return (0);
}

Write a program for 1 232 34543 4567654?

Here, We write a program for given query.

int main()
{
    int i,j,k,l=0,n;
    printf("Enter the given length\n");
    scanf("%d",&n);
    for(i=1;i<=n;i++)
    {
       k=2;
       for(j=0;j

What does exit() do?

It is used to comes out of execution normally.

What is the difference between memcpy and strcpy?

The key difference between memcpy and strcpy are given below:

1.memcpy is used to copy the NULL bytes even if size is not mentioned,Where as strcpy is stopped copying when it encounters NULL bytes.
2.memcpy can copy null bytes also if the size of memory is given strcpy stops after the first null byte. 
 

How can we handle exceptions in C?

In C we handle exceptions without using try,catch block.Which i used in java,C++ etc.But we can handle exception using validation of data from out side of the world.
Example:
void main()
{
   int m,n,divide;
   scanf("%d,%d",m,n);
   divide=m/n;
   printf("%d",divide);
}
In this n may be zero,that generate exception.So,we can avoid them using if statement.
if(n==0)
        print("you have to enter non-zero value");
Using this we only prevent from exception not handle it.

How to compare two strings without using the strcmp() function?

I have given you a example.In this we compare two strings str1 and str2 without using the strcmp() function.
Example:

#include 
#include 
void stringcompare(char str1[], char str2[]);
int main()
{
   char string1[10],string2[10];
   printf("\nEnter first String:");
   scanf("%s",string1);
   printf("\nEnter second String:");
   scanf("%s",string2);
   stringcompare(string1,string2);
   return 0;
}
void stringcompare(char *str1, char *str2)
{
   int i,j;
   for(i=0;str1[i]!='\0';i++)
   {
      for(j=0;str2[j]!='\0';j++)
      {
          if(str1[i] == str2[j])
          continue;
      }
   }
   if (i==j)
   {
       printf("String str1:%s and str2:%s are EQUAL\n",str1,str2);
   }
   else
     printf("String str1:%s and str2:%s are NOT EQUAL\n",str1,str2);
}

How to access or modify the constt variable in C ?

We can not modify the constant variable.

What is an volatile variable?

We can not modify the variable which is declare to volatile during execution of whole program.
Example:
volatile int i = 10;
 value of i can not be changed at run time.

How the processor registers can be used in C?

using keyword register we can use the process register in C.Basically process register is used to store variables those i want to access frequently.if these registers are not used in any other program,then those registers we used to 
allocate memory these variables.

IF **p and &(*p) are same, than tell how?

No, **p and &(*P) are not same. Because of &(*P) is used to point the address of variable that was stored in p.Where as **p is used to point the pointer to the another pointer.  

Can you write function similar to printf()?

Here, we write a program similar to printf().

#include 
int printf(const char * restrict fmt, ...) 
{
   va_list list;
   int i;
   va_start(list, fmt);
   i = vfprintf(stdout, fmt, list);
   va_end(list);
   return i;
}

How to use functions fseek(), freed(), fwrite() and ftell()?

We can use fseek(),fread(),fwrite() and ftell() functions like that,

fseek(f,1,item)->Move the pointer for file f a distance 1 byte from location item.

fread(s,item1,item2,f)->Enter item2 data items,each of size item1 bytes,from file f to string s.

fwrite(s,item1,item2,f)->send item2  data items,each of size item1 bytes from string s to file f.

ftell(f)->Return the current pointer position within file f.
Functions fread,fseek and fwrite returned type is int and ftell is long int.

What do you understand about datatype?

C Language has supported many data types.Which we use writing program.C Language gave authority to programmers to create and use datatypes.

Below i have shown you list of basic data types.That are introduce by ANSI standard.

datatypes in C:

char: required 1 byte and it used for characters  or integer variables.
int: required 2 or 4 bytes and it used for integer values.
float: required 4 bytes and it used for Floating-point numbers.
double: required 8 bytes and it used for Floating-point numbers.  

What are the data type modifiers?

Some data types are to used to effect the characteristic of data object.These are called modifiers.Below i have shown you some modifiers:

Data type modifiers in C:

long: Forces a type int to be 4 bytes (32 bits) long and forces a type double to be larger than a double (but the actual size is implementation
defined).
short: Forces a type int to be 2 bytes (16 bits) long. 
unsigned: Causes the compiler (and CPU) to treat the number as containing only positive values. Because a 16-bit signed integer can hold values between �32,768 and 32,767, an unsigned integer
can hold values between 0 and 65,535. The unsigned modifier can be used with char, long, and short (integer) types.

what are the constants?Explain in brief?

When we declare any variable as constant than we can't be modify the value of that variable at run time.Constants can come in any data type that the C compiler supports. A special constant, the string, can be used to either initialize a character array or be substituted for one. 
Some constant in C:

123: int,In the smallest size and type that will hold the value specified.
123U: unsigned int,in the smallest size and type that will hold the value specified.
123L: long int,signed
123UL: long int,unsigned
'A': Character constant
"ABCD": Character string constant
7.89:double-floating-print constant
7.89F:float-floating-print constant
7.89F:long double-floating-point constant

How to differentiate b/n definition and declaration?

Some useful difference b/n definition and declaration are given below:

When define an object not only its attribute are made known,but its object are also created.Where as when we declare an object only its attribute are made known. 
Example:
We define object like;
long int lSum; 
long int lCount;
void SumInt(int nItem)
{
   lSum =lSum + (long)nItem;
   ++lCount;
}

We declare an object like;
void VFunction(int nType)
{
   int nTest;
   nTest = nType;
}

How to define their types of variables and initialize them?

Variables are made by programmers.It can be modified.When we defined any data object as a singular variable can be defined also as an array.
  In C variable are of many type. Like: an integer or character, or may be of compound data objects(Like: structure or unions). 
Initialization of variable:

int num; //Here we declare num variable as  integer and it is initialized as default size.

int num=0; //Here we declare num variable and initialize them with 0.

What is type casting?Explain it with an example?

The key role of type casting is that converting a variable of one type into anther type.
Given below i have shown you a example of conversion of data types in C:
Original    Original    Type casting After type 
data type   in decimal               casting

long int    123123123   to short int 46515
short int   12345       to char      '9'
long double 123123123123to integer   2864038835   

What are the Array?How to define and declare them?

Basically Array are the collection of same data type.It has common name and addressed as a group.

Declaration of an Array:
We have to declare Array also as a single data object.
int Array[10];
 In this array of integers are created.Than first member in the array are addressed as Array[0] and last member has been declared as Array[9].
Example:
#define MAX_SIZE 10
int Array[MAX_SIZE];
int n;
for (n = 1; n <= MAX_SIZE; n++)
{
   Array[n] = n;
}  

Definition of an Array:
We know that we declare an array like that,
int Array[10];
  When an array is external, it must be defined
in any other source files that may need to access it. Because you don�t want the compiler
to reallocate the storage for an array, you must tell the compiler that the array is allocated externally and that you want only to access the array.

What are the Array Indexing?explain.

What do you understand about String?Explain it.

Basically C does not support an String.But C has many library functions using them we can over come that problem.
  String are Array of type char.String constant(like: "this is our first string")can be consider as Character Array.

What are the reserved Keywords?Explain it.

Some keywords are reserved in ANSI C.This keyword we can use as such they have given.Before using those keywords keep one thing in mind the are lowercase.Some main ANSI C reserved are given below:

asm: Begins assembly code and is not part of the ANSI standard.
FORTRAN: The entry follows FORTRAN calling conventions; FORTRAN
may be in lowercase for some implementations and
is not part of the ANSI standard.
PASCAL: The entry follows PASCAL calling conventions; PASCAL
may be in lowercase for some implementations and is not
part of the ANSI standard. Generally, the PASCAL conventions are identical to FORTRAN�s.
const: The variable will be used as a constant and will not be modified.
volatile: The compiler may make no assumptions about whether the
variable�s value is current. This keyword limits optimization,
and possibly slows program execution.
signed: The variable is a signed integer (with the actual size unspecified).
auto: The variable is created when the function is called, and is
discarded when the function exits. An auto variable is not initialized by the compiler.
continue: Passes control to the next iteration of a do(), for(), or while() statement.
enum: An integer defining a range of values. The actual internal representation of the value is not significant.
extern: The object is defined in a different source file.

What are the ANSI reserved names in C?

I have given you a ANSI C reserved names and their uses given below:

%: This is used to printf()/scanf() format string.

is..or to..: Lowercase function names beginning with either is or to,where the next character also is a lowercase letter.

str..,mem..or wcs..: Lowercase function names beginning with either str, mem, or wcs, where the next character also is a lowercase letter

E: Macros that begin with an uppercase E

SIG.. or SIG_..: Macros that begin with either an uppercase SIG or SIG_

...f or ...l: Existing math library names with a trailing f or l

LC_: Macros that begin with an uppercase LC_

What are the pointers?How to declare them?

Pointers are may be of variable or constant.The contains the address of object.Some important characteristics of pointers are given below:

1.Pointer is used to contain the address of any object.It may be an array,a singular variable,a union and a structure.
2.It is also used to store the address of a function.
3.It can not hold the address of the constant.
 Remember that when a pointer getting incremented than its value is incremented by the sizeof() the pointer's type.
 We can declare and initialize the pointer like that:
int counter= 0;
int *pcounter;
 pcounter = &counter;


   

What are the Indirection?Explain with an example?

You have a pointer, what do you do with it? Because it�s part of your program,you can�t write your address on it and nail it to a tree so that your friends can find your home. You can, however, assign to a pointer the address of a variable and pass it to a function, and then the function can find and use the variable.
  C operator * is called the indirection operator.C to use whatever the pointer variable is pointing to and use the value contained in the memory that the pointer is pointing to.

What are the Function Pointer?Explain with an example?

 Using function pointer we can do almost anything with function name.We can pass parameters to a function that is called as pointer.A classic
example is the library function qsort(), which takes a pointer to a function. This pointer often is coded as a constant; you might, however, want to code it as a function pointer variable that gets assigned the correct function to qsort()�s compare.
I have given you a example of Function pointer.

function named function() is defined which will be called through a function pointer. A function named caller() accepts as parameters a function pointer and an integer, which will be passed as arguments to the function that will be called by caller(). 

#include 
static void function(int a)
{
   printf("function: %d\n", a);
}
static void caller(void (*func)(int), int p)
{
   (*func)(p);
}
int main(void)
{
   caller(function, 10);
   return 0;
}

What are the Bit Operators?

Bit operators are different frm logical operator. So,don't confuse with them.The keyword TRUE signifies a true bit (or bits) that is set to one,
and FALSE signifies a bit (or bits) that is set to zero. 
Some Bitwise Operators are given below:

&: Performs a bitwise AND operation. If both operands are TRUE, the result is TRUE; otherwise, the result is FALSE.
|: Performs a bitwise OR operation. If either operand is TRUE, the result is TRUE; otherwise, the result is FALSE.
^: Performs a bitwise exclusive OR operation. If both operands are TRUE or both operands are FALSE, the result is FALSE. The result is TRUE if one operand is TRUE and the other is FALSE. Exclusive OR is used to test to see that two operands are different.
<<: Shifts the X operand, Y operand bits to the left. For example, (1 << 4) returns a value of 8. In bits, (0001 << 4) results in 1000. New
positions to the left are filled with zeroes. This is a quick way to multiply by 2, 4, 8, and so on.  
>>: Shifts the X operand, Y operand bits to the right. For example, (8
>> 4) returns a value of 1. In bits, (1000 >> 4) results in 0001. New positions to the right are filled with ones or zeroes, depending on the value and whether the operand being shifted is signed. This is a quick way to divide by 2, 4, 8, and so on.
// Using a bitwise AND:
if (x & y)
{
// With x == 1, and y == 2, this will NEVER be TRUE.
}

What are the External Variables?

We use single include file to create both a definition and a declaration for an external variable.Scope of external variable is global.Every byte of memory allocated for an external variable is initialized to zero. 

How to define structure in C?

To define structure in C we use struct keyword.
Using structure we can form different groups according to their specialty.
Syntax of defining an structure are given below:
struct tag_name {
  type member_name;
  type member_name;
  type member_name;
} structure_name = {initializer_values};
Example of an structure:

#include  
#include  int main(void); 
int main()
{
int i;
struct
{
   char szSaying[129];
   int nLength;
} MySaying = {�Firestone�s Law of Forecasting:�,
strlen(MySaying.szSaying)};
printf(�sizeof(MYSaying)=%d\n�, sizeof(MySaying));
printf(�MySaying %p%3d�%s�\n�, &MySaying.szSaying,
MySaying.nLength, MySaying.szSaying);
printf(�\n\n�);
return (0);
}

How do u understand about structures of arrays?

How do you define offsetof() Macro?

ANSI C introduce a new macro called offsetof().This is use to determine the offset of a member in a structure.
  Using offsetof() we can easy to compute the amount of storage used by individual members of a structure.
Example of offsetof() macro are given below:

#include 
#include 
#include 
#include 

struct foo {
  char *bar;
  int number;
};
// Print a foo the hard way
void printFoo(void *foo) {
   printf("foo->bar: %s\n", *(char **) (foo +   offsetof(struct foo, bar)));
   printf("foo->number: %d\n", *(int *)(foo + offsetof(struct foo, number)));
}
int main() 
{
   struct foo foo = {"A foo", 18};
   printFoo(&foo);
}

What the use of malloc() function?

malloc() function is used for memory allocation in ANSI C standard.malloc() function requires only one parameters. 
For using malloc() function we have to follow some rules. Which are given below:

1.The malloc() function returns a pointer to the allocated memory or NULL if the
memory could not be allocated.
2.The pointer returned by malloc() should be saved in a static variable, unless you are sure that the memory block will be freed before the pointer variable is discarded at the end of the block or the function.
3.You should always free a block of memory that has been allocated by malloc()when you are finished with it. If you rely on the operating system to free the block when your program ends, there may be insufficient memory to satisfy
additional requests for memory allocation during the rest of the program�s run.
4.Avoid allocating small blocks (that is, less than 25 or 50 bytes) of memory.There is always some overhead when malloc()allocates memory�16 or more bytes are allocated in addition to the requested memory.

What are the different types of malloc() function in C?

Some malloc() functions of C with their function and description are given below:

void * malloc( size_t size ); : The ANSI C standard memory allocation function.
void _ based( void ) *_bmalloc( _ segment seg, size_t size ); : Does based memory allocation.The memory is allocated from the segment you specify.
void _ far *_fmalloc( size_tsize ); : Allocates a block of memory outside the default data segment,
returning a far pointer. This function is called by malloc()when the large or compact memory model is specified. 
void _ near *_nmalloc( size_t size ); : Allocates block of memory inside the default data segment, returning a near pointer. This function is
called by malloc() when the small or medium memory model is specified.

What is the use of calloc() function?

Calloc() function is used to initialize memory. Calloc() function is used to allocates a group of object.
Syntax of allocating Calloc() function are given below:
void *calloc(size_t number, size_t size);
Where,
size_t-> is a synonym for unsigned.
number-> is the num of object to allocate.
size-> It shows the size of each object in bytes.
  When memory allocation with calloc() function is successful,than function returns a pointer.
Otherwise,it returns 0.
Example:
#include 
#include 
main()
{   
    unsigned number;
    int *pointer;
    printf("Enter the num(int)to allocate: ");
    scanf("%d", &number);
    pointer = (int*)calloc(number, sizeof(int));
    if (pointer != NULL)
    puts("successful Memory allocation .");
    else
    puts(" failed Memory allocation.");
    return(0);
}
  

What are the different type of calloc() function?

Some main calloc() function with their description are given below:

      Function               Description     
void *calloc(size_t num, The ANSI C standard array
size_t size );           memory allocation  
                         function.    
void _ based(void)       Using this you can write 
*_bcalloc( _segment seg, the segment that the  
size_t num, size_t size );data will be allocated 
                          from.
void _ far *_fcalloc     Allocates a block of 
(size_t num,size_t size);memory outside the
                         default data segment,
                         return far pointer.We  
                         call this function when
                         big mem model is used.  
void_near*_ncalloc       Allocates a block of 
(size_t num,size_t size);memory inside the 
                        default data segment,
                        return near pointer. 
                        This function is used 
                        when small/medium memory 
                        model specified.        

How to use free() function?

Free() function is used to return the memory to the operating system after use.Because is most of time very limited source.So,we have to try to made max output.
Example:
#include 
#include 
int main ()
{
   int *R1, *R2, *R3;
   R1 = (int*) malloc (10*sizeof(int));
   R2 = (int*) calloc (10,sizeof(int));
   R3 = (int*) realloc (R2,50*sizeof(int));
   free (R1);
   free (R3);
   return 0;
}  

How to differentiate local memory and global memory?

Local and global memory allocation is applicable with Intel 80x86 CPUs.
Some main difference b/n local and global variables are given below:

1.Using local memory allocation we can access the data of the default memory segment,Where as with global memory allocation we can access the default data,located outside the segment,usually in its own segment.   
2.If our program is a small or medium model program , the default memory pool is local,Where as If our program uses the large or compact memory model, the default memory pool is global.

What is the significance of disk files?

Without files it is impossible to make program. Because without input we can't expect about output
and unable to save result without files.ANSI C has huge collection of I/O functions.These files are called disk files.
 Programmer can made a file in an unformatted (machine readable) manner,or program can write to a file in a formatted (people readable) manner. 

What are the Text Files and Binary Files?

Text Files: Text Files are those files that are display on the screen.These files are readable files.It has not uses only few special characters like,tab and newlines.Text Files generally introduce by programmers.
Binary Files: Binary Files are those files that can contain any data, including the internal representation of numbers, special control characters.
  

What are the temporary disk files?How to create them?

All most large programs with large with large data objects do not even try to save all their data
in memory.they only read the data,index the data,and than than write the file in Temporary disk files.  
  Some rules of creating files are given below:
1.The file name must be unique. This uniqueness can be guaranteed by using tmpfile() or tmpnam().
2.The file must be deleted when you have finished using it. If you create the file using tmpfile(), the operating system deletes the file for you. If you create it with tmpnam() and an explicit open, your program must delete the file.

Syntax of creating files are given below:
FILE *TempFile = tmpfile();
     // Lines of code to use the file 
fclose(TempFile);

What are the stream files?

We can open file in C with using stream files.which are identified with a pointer to a FILE structure, or as low-level files, which are identified with an integer handle.
  We ca open stream files with using one of the following functions.
fopen(): Opens the specified file with the specified mode
freopen(): Closes the file specified, then opens a new file as specified
fdopen(): Opens a duplicate stream file for an already open low-level file

What are the stdin and stdout file?

We can open stdin file using operating system. Basically it touched with keyboard.It comes from an I/O redirected file.
  Some functions used by stdin are given below:
getchar(): Use to get character from stdin
gets(): Use to get a string from stdin
scanf(): Use to performs a formatted read from stdin

stdout�s output goes to a redirected file.Program to use the screen by opening a file called con.
  Some functions used by stdin are given below:
printf(): Use to performs a formatted write to stdout
putchar(): use to writes a character to stdout
puts(): Writes the buffer to stdout
vprintf(): Performs a formatted write to stdout. The output is pointed to by a parameter-list pointer.

What is the stdaux file?

First i tell you about about aux device.We can defined aux device as the main serial communication port (not the console serial communication port).
  aux is defined as COM1: and stdaux writes to the COM1: port.
Example:
#include  
#include  
#include  // Standard include items
#include  // For exit()
int main( // Define main() and the fact of program
int argc, // uses the passed parameters
char *argv[],
char *envp[]
);
int main(int argc,char *argv[],char *envp[])
{
   int i;
   for (i = 0; i < 100; i++)
   {
     /* Because stdaux is opened in the binary 
        mode,* CR/LF must be supplied explicitly, 
        using \n\r*/
      fprintf(stdaux,
     �Line %2d of 100 lines�
     � being written to stdaux by a program.\n\r�,
     i);
}
return (0);
}

What do you understand about Direct port I/O?

Direct Port I/O are of system dependent from type of computer and configuration of computer.It may be dangerous when we use this uncarefully.
 Some main Direct I/O functions are given below:
inp(): Use to Inputs a byte of data from the specified port
inpw(): Use to Inputs two bytes of data from the specified port  
outp(): Use to Outputs a byte of data to the specified port
outpw(): Outputs two bytes of data to the specified port
  Always it returns type int,All output function returns in terms of byte or word and input function return currently input byte or word.

What is the data management?Also define Sorting, merging and purging, Indexed files?

In data management we consider two things: 'what to manage' and 'how to manage'.What to manage is very important because in that we consider about Additional and accompanying information, chiefly documentation, code and command files.
 For achieving that we uses many methods like sorting,merging,purging and indexed files.

Sorting: We use that to sort data in a particular manner as our need.It increase the searching of data efficiently.
Merging: This is used to combine two sorted files and generate a resultant sorted files.
Purging: It is uses to create the new file from the sorted file and eliminate the duplicate lines of the original file from the sorted files.
Indexed file: It consists of two files.main data file and smaller index file.
                                          

What are the Linked List?

Basic definition of linked list is that An linked list is a list of data items in which each data item points to the next data item(except last item).
  In linked list we start with a pointer that points to the first element of the list.after that next element points to its successor element.Last element has a NULL pointer that indicates the end of the list. 
  Linked are of three type:
1.Doubly linked list
2.Ordered linked list
3.Circular Linked list
  We construct linked list using these functions:
LinkedList()//It is used to construct an empty list. 
LinkedList(Collectionc)//It is used to construct a list elements with specific location.   

What is the Double LinkedList?

Double Linked List is that each data item in the list can point both side(next or previous)data item.
It is not specific type means it may be of stack or queue.This is use to increase the performance of program.It is also called as Two-way Linked List or
Symmetrically Linked list.

What is the difference b/n Linear search and Binary search?

The main difference b/n Linear search and Binary search are given below:
Linear search: Linear search starts to search first records of the list and going on until it finds the matched record or to the end of list.In Linear Linked list their is no need to sort the file in a particular order.

Binary search: Their is three steps you have to follow when you using Binary search.

1.It starts with to select the middle item of the list.When the key item is less than the selected item than Binary search take the item between the current item and the start element of the list.Otherwise, if key item is greater than the selected item than Binary search take the item between the current item and the last element of the list.Benefit of its is that after taking one comparison it delete the half list.
2.If key item is less than the current item than we only take half list who is less than the key.Otherwise,If key item is greater than the current item than we only take half list who is greater than the key.And start in again.
3.We repeat step2 till we not reached our desired key.    

What do you understand about B-Tree?

When we uses B-Tree. Each data object has a key, all the key who are less than the given are placed on left side where as key who are greater than the given key are placed on the right side. Using this method key maintain a tree like structure for the given list of item.Some, Important terms that we generally used in B-Tree are given below:

Node: Indicates the data items 0f the list in B-Tree. 
Root node: Indicates the first node in B-Tree.
Left side: Which data items on the left side and less than the current item.
Right side: Which data items on the Right side and greater than the current item.
balance: This is use to check the tree is balance or not.

What is Thrashing?

Thrashing is that in which a computer takes the much type to load the data from secondary memory to main memory or main memory to secondary memory as compare to execution of loaded data.
  When we divide memory into pages than thrashing from this is called 'page thrashing'. 

What is a pragma?

# pragma preprocessor directive is use to allow the compiler to do the some specific operation of compiler.pragma has on and off command using them we can enable or disable some compiler operations.
 Suppose, In our program  loop does not perform his operation may be it happen because of pragma.
1.If we want to enable the operation of loop using pragma. Than we have to write like that,
#pragma loop_opt(on)

2.If we want to disable the operation of loop using pragma. Than we have to write like that,
#pragma loop_opt(off)
   

What is the difference between the Heap and the Stack?

The main difference b/n the Heap and the Stack are given below:

1.In stack we create object temporary where programmer used to reserve allocation.'
2.stack not have automatic garbage collection where as heap have automatic garbage collection.

Why n++ executes faster than n+1?

n++ executes faster than n+1 because n++ want only one instruction for execution where n+1 want more one instruction for execution. 

What is the difference b/n a linker and linkage?

The key difference b/n linker and linkage is that linker is used to change an object code into an executable code by linking together the necessary build in functions.Place where we declare the variable in a program is called the linkage of variable.

What is the difference b/n run time binding and compile time binding?

When the address of functions are determined a run time than it is called run time or dynamic binding or late binding.While when the address of functions are determined a compile time than it is called compile time or static binding or early binding.

Write algorithm to reverse a singly linked list.

write algorithmto reverse a singly link list 

WHAT IS LIMITATIONS IN C?

How to use functions in arrarys? it gives a linker error that function is not defined!!

Write a program to find the squares of n number using do-while.

sum of all number in between range use recursive function.

what happen if we declare a constructor after destructor?

Write a progarm to count number of vowels,consonant,digit spaces and other character type.

what is hashing?

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

Write c program to print all even numbers from 56 to 76 including 56 and 76 using loop.

Explain pointer with the help of an example.

i have an assignement in wihich i have to print a triangle like this: 1 1 2 3 1 2 3 4 5 1 2 3 4 5 6 7 1 2 3 4 5 6 7 8 9 please help me how do i print this?

In the following figure: A B C D E F G H I Each of the digits 1, 2, 3, 4, 5, 6, 7, 8, and 9 is: a)Represented by a different letter in the figure above. b)Positioned in the figure above so that each of A + B + C,C + D +E,E + F + G, and G + H + I is equal to 13. Which digit does E represent? how to solve that type of question.........

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 Nested looping structure C programs

What are macros?

What is a NULL pointer?

A ptr that is not pointing to any valid programming address is called as null ptr.also it can point to 0x0000
If trying to deference the null ptr in c,its throws segmentation fault.

How is it different from an unutilized pointer?

How is a NULL pointer defined?

Int *p=NULL:

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

How do you reverse a singly linked list?

How do you reverse a doubly linked list?

How do you sort a linked list?

Write a C program to sort a linked list.

How do you reverse a linked list without using any C pointers?

How would you detect a loop in a linked list? Write a C program to detect a loop in a linked list.

Write a C program to find the depth or height of a tree.

Write a C program to determine the number of elements (or size) in a tree.

Write a C program to delete a tree (i.e, free up its nodes)

Write C code to determine if two trees are identical.

Write a C program to find the minimum value in a binary search tree.

Write a C program to compute the maximum depth in a tree?

Is that possible to pass a structure variable to a function/ If so,explain the detailed ways?

yes  it is possible to pass structure variable to a function
struct emp
{
   int eno;

};
void disp(struct emp e)
{
printf(e.eno);
}
void main()
{
struct emp e;
e.eno=10;
disp(e);
}
  

write a c program to accept a number between 3 & 10 & print a square of stars. if user enters 4 the output should be as shown **** * * * * ****

#include 
main()
{
        int count;
  printf("\n**************");         

  for( count = 1 ; count <= 8 ; ++count)
    print f("\n*            *");       

  printf("\n**************\n");       
  
}

What is C?

c is super set of all language

string constants should be enclosed with a.single quotes b.double quotes

double quotes 

Which of the following is the structure of an if statement? A. if (conditional expression is true) thenexecute this codeend if B. if (conditional expression is true)execute this codeend if C. if (conditional expression is true) {then execute this code>->} D. if (conditional expression is true) then {execute this code}

d

Different data types for different types of data in C

Different data types for different types of data in C are 

Primary Data Types
Secondary Data Types

Data Type in C

There are many data type for different different Purposes.

int
unsigned long long int
float
long long int
unsigned long int
long int
unsigned int
unsigned short int
short int 
double
char
signed char
unsigned char
long
long double

Storage Class in C

4 Storage Classes in C language :

1.auto
2.register
3.static
4.extern

Different Format Specifier in C

int : %d
float : %f
char : %c
string : %s
address : %u
etc.