Jump to content
ChetanaSforum
Ravi

(FAQ) Interview FAQ in C Language

Recommended Posts

Try to answer these questions frens. All these are asked in various interviews.

ravi

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

What does static variable mean?

What is a pointer?

What is a structure?

What are the differences between structures and arrays?

In header files whether functions are declared or defined?

What are the differences between malloc() and calloc()?

What are macros? what are its advantages and disadvantages?

Difference between pass by reference and pass by value?

What is static identifier?

Where are the auto variables stored?

Where does global, static, local, register variables, free memory and C Program instructions get stored?

Difference between arrays and linked list?

What are enumerations?

Describe about storage allocation and scope of global, extern, static, local and register variables?

What are register variables? What are the advantage of using register variables?

What is the use of typedef?

Can we specify variable field width in a scanf() format string? If possible how?

Out of fgets() and gets() which function is safe to use and why?

Difference between strdup and strcpy?

What is recursion?

Differentiate between a for loop and a while loop? What are it uses?

What are the different storage classes in C?

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

What is difference between Structure and Unions?

What the advantages of using Unions?

What are the advantages of using pointers in a program?

What is the difference between Strings and Arrays?

In a header file whether functions are declared or defined?

What is a far pointer? where we use it?

How will you declare an array of three function pointers where each function receives two ints and returns a float?

what is a NULL Pointer? Whether it is same as an uninitialized pointer?

What is a NULL Macro? What is the difference between a NULL Pointer and a NULL Macro?

What does the error 'Null Pointer Assignment' mean and what causes this error?

What is near, far and huge pointers? How many bytes are occupied by them?

How would you obtain segment and offset addresses from a far address of a memory location?

Are the expressions arr and &arr same for an array of integers?

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

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

What is the similarity between a Structure, Union and enumeration?

Can a Structure contain a Pointer to itself?

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

How are Structure passing and returning implemented by the complier?

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

What is the difference between an enumeration and a set of pre-processor # defines?

what do the 'c' and 'v' in argc and argv stand for?

Are the variables argc and argv are local to main?

What is the maximum combined length of command line arguments including the space between adjacent arguments? If we want that any wildcard characters in the command line arguments should be appropriately expanded, are we required to make any special provision? If yes, which?

Does there exist any way to make the command line arguments available to other functions without passing them as arguments to the function?

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

To which numbering system can the binary number 1101100100111100 be easily converted to?

Which bit wise operator is suitable for checking whether a particular bit is on or off?

Which bit wise operator is suitable for turning off a particular bit in a number?

Which bit wise operator is suitable for putting on a particular bit in a number?

Which bit wise operator is suitable for checking whether a particular bit is on or off?

which one is equivalent to multiplying by 2:Left shifting a number by 1 or Left shifting an unsigned int or char by 1?

Write a program to compare two strings without using the strcmp() function.

Write a program to concatenate two strings.

Write a program to interchange 2 variables without using the third one.

Write programs for String Reversal & Palindrome check

Write a program to find the Factorial of a number

Write a program to generate the Fibinocci Series

Write a program which employs Recursion

Write a program which uses Command Line Arguments

Write a program which uses functions like strcmp(), strcpy()? etc

What are the advantages of using typedef in a program?

How would you dynamically allocate a one-dimensional and two-dimensional array of integers?

How can you increase the size of a dynamically allocated array?

How can you increase the size of a statically allocated array?

When reallocating memory if any other pointers point into the same piece of memory do you have to readjust these other pointers or do they get readjusted automatically?

Which function should be used to free the memory allocated by calloc()?

How much maximum can you allocate in a single call to malloc()?

Can you dynamically allocate arrays in expanded memory?

What is object file? How can you access object file?

Which header file should you include if you are to develop a function which can accept variable number of arguments?

Can you write a function similar to printf()?

How can a called function determine the number of arguments that have been passed to it?

Can there be at least some solution to determine the number of arguments passed to a variable argument list function?

How do you declare the following: An array of three pointers to chars An array of three char pointers , A pointer to array of three chars, A pointer to function which receives an int pointer and returns a float pointer , A pointer to a function which receives nothing and returns nothing .

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

Does there exist any other function which can be used to convert an integer or a float to a string?

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

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?

How would you use the functions sin(), pow(), sqrt()?

How would you use the functions memcpy(), memset(), memmove()?

How would you use the functions fseek(), freed(), fwrite() and ftell()?

How would you obtain the current time and difference between two times?

How would you use the functions randomize() and random()?

How would you implement a substr() function that extracts a sub string from a given string?

What is the difference between the functions rand(), random(), srand () and randomize()?

What is the difference between the functions memmove() and memcpy()?

How do you print a string on the printer?

Can you use the function fprintf() to display the output on the screen?

Share this post


Link to post
Share on other sites

Hi ravi,

Its Himanshu...I think I can give answers of most of the questions so just send me ur selected questions on hik4uonly@yahoo.com...waiting 4 ur reply...yeak sharing is the best way to explore & acess our knowledge...

bye...tc...

Himanshu R Khatri

Try to answer these questions frens. All these are asked in various interviews.

ravi

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

What does static variable mean?

What is a pointer?

What is a structure?

What are the differences between structures and arrays?

In header files whether functions are declared or defined?

What are the differences between malloc() and calloc()?

What are macros? what are its advantages and disadvantages?

Difference between pass by reference and pass by value?

What is static identifier?

Where are the auto variables stored?

Where does global, static, local, register variables, free memory and C Program instructions get stored?

Difference between arrays and linked list?

What are enumerations?

Describe about storage allocation and scope of global, extern, static, local and register variables?

What are register variables? What are the advantage of using register variables?

What is the use of typedef?

Can we specify variable field width in a scanf() format string? If possible how?

Out of fgets() and gets() which function is safe to use and why?

Difference between strdup and strcpy?

What is recursion?

Differentiate between a for loop and a while loop? What are it uses?

What are the different storage classes in C?

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

What is difference between Structure and Unions?

What the advantages of using Unions?

What are the advantages of using pointers in a program?

What is the difference between Strings and Arrays?

In a header file whether functions are declared or defined?

What is a far pointer? where we use it?

How will you declare an array of three function pointers where each function receives two ints and returns a float?

what is a NULL Pointer? Whether it is same as an uninitialized pointer?

What is a NULL Macro? What is the difference between a NULL Pointer and a NULL Macro?

What does the error 'Null Pointer Assignment' mean and what causes this error?

What is near, far and huge pointers? How many bytes are occupied by them?

How would you obtain segment and offset addresses from a far address of a memory location?

Are the expressions arr and &arr same for an array of integers?

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

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

What is the similarity between a Structure, Union and enumeration?

Can a Structure contain a Pointer to itself?

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

How are Structure passing and returning implemented by the complier?

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

What is the difference between an enumeration and a set of pre-processor # defines?

what do the 'c' and 'v' in argc and argv stand for?

Are the variables argc and argv are local to main?

What is the maximum combined length of command line arguments including the space between adjacent arguments? If we want that any wildcard characters in the command line arguments should be appropriately expanded, are we required to make any special provision? If yes, which?

Does there exist any way to make the command line arguments available to other functions without passing them as arguments to the function?

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

To which numbering system can the binary number 1101100100111100 be easily converted to?

Which bit wise operator is suitable for checking whether a particular bit is on or off?

Which bit wise operator is suitable for turning off a particular bit in a number?

Which bit wise operator is suitable for putting on a particular bit in a number?

Which bit wise operator is suitable for checking whether a particular bit is on or off?

which one is equivalent to multiplying by 2:Left shifting a number by 1 or Left shifting an unsigned int or char by 1?

Write a program to compare two strings without using the strcmp() function.

Write a program to concatenate two strings.

Write a program to interchange 2 variables without using the third one.

Write programs for String Reversal & Palindrome check

Write a program to find the Factorial of a number

Write a program to generate the Fibinocci Series

Write a program which employs Recursion

Write a program which uses Command Line Arguments

Write a program which uses functions like strcmp(), strcpy()? etc

What are the advantages of using typedef in a program?

How would you dynamically allocate a one-dimensional and two-dimensional array of integers?

How can you increase the size of a dynamically allocated array?

How can you increase the size of a statically allocated array?

When reallocating memory if any other pointers point into the same piece of memory do you have to readjust these other pointers or do they get readjusted automatically?

Which function should be used to free the memory allocated by calloc()?

How much maximum can you allocate in a single call to malloc()?

Can you dynamically allocate arrays in expanded memory?

What is object file? How can you access object file?

Which header file should you include if you are to develop a function which can accept variable number of arguments?

Can you write a function similar to printf()?

How can a called function determine the number of arguments that have been passed to it?

Can there be at least some solution to determine the number of arguments passed to a variable argument list function?

How do you declare the following: An array of three pointers to chars An array of three char pointers , A pointer to array of three chars, A pointer to function which receives an int pointer and returns a float pointer , A pointer to a function which receives nothing and returns nothing .

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

Does there exist any other function which can be used to convert an integer or a float to a string?

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

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?

How would you use the functions sin(), pow(), sqrt()?

How would you use the functions memcpy(), memset(), memmove()?

How would you use the functions fseek(), freed(), fwrite() and ftell()?

How would you obtain the current time and difference between two times?

How would you use the functions randomize() and random()?

How would you implement a substr() function that extracts a sub string from a given string?

What is the difference between the functions rand(), random(), srand () and randomize()?

What is the difference between the functions memmove() and memcpy()?

How do you print a string on the printer?

Can you use the function fprintf() to display the output on the screen?

Share this post


Link to post
Share on other sites

What is a pointer? pointer is variable use to point the memory location;it always store integer type variable.What is a structure? structure is user defined data type, it is grouping of various data type.What are the differences between structures and arrays? structure is use to grouping the different data type where as array is use to grouping the similar data type.In header files whether functions are declared or defined? in header file function are defined.What are the differences between malloc() and calloc()? memory allocated by malloc function contain garbage value where as memory allocated by calloc fun contain 0 value i.e initialize by 0.What are macros? what are its advantages and disadvantages? macros is use to give a name of series of statement, include the exixting filename whice has defined by various function,use for the declare constant var.Difference between pass by reference and pass by value? in pass by reference we are passing the address of the variablein pass by value we are passing a copy of contain of variableWhere are the auto variables stored? by default we declare the variable are auto variable. which contain we can manupalet whenever we want. Difference between arrays and linked list? array declare memory statically whereas linked list declare it dynamically.

Share this post


Link to post
Share on other sites

Hi, did anybody got the answers for these qtns, then kindly mail me to tharikishore48@yahoo.comtharikishore_1984@yahoo.com plzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz.

Share this post


Link to post
Share on other sites

Hi All :) ,

 

I am posting ans for the ques. I have tried in past several times but got error :( . Then I was busy with my job. As I have no work since last few days, I tried my hand once again. Hope it will work.

 

Q: What does static variable mean?

A: They are stored in memory. Default initial value is zero. Their scope is local to the block in which the variable is defined & value of the variable persists between different function calls. Avoid using static unless we need it. Because their values are kept in memory when the variables are not active, which means they take up space in memory that could otherwise used by other variables.

 

Q: What is a pointer?

A: Pointer is an address variable which contains address of another variable. Pointer operators are * and &. int pointer contains address of int quantity, float contains float quantity, same holds good for each data type even for user defined data types. Maximum size of pointer is 2 bytes.

 

Ex of pointer declaration:

int a=27;

int *p;p=&a; OR int *p=&a;

Q: What is a structure?

A: A structure is a collection of one or more variables, possibly of different data types, grouped together under a single name for convenient handling.

Q: What are the differences between structures and arrays?

A: In array we can store variables of same data type while in structure we can store variables of different data types. In C++ structure, we can add function also to the structure.

Q: In header files whether functions are declared or defined?

A: Functions are declared in header files & defined in the program. This can be explained as – if we use printf() without including stdio.h then it will show complile time error as function should have prototype. With this function prototype compiler came to know which type of functions we r using. That's why function prototype should be given before using predefined or userdefined functions.

Q: What are the differences between malloc() and calloc()?

A: Both these functions are declared in alloc.h & are used to dynamic memory allocation of a variable. Difference is that: malloc() takes only one argument while calloc() will take two arguments.

Ex: Suppose we have to dynamically alloc memory for 10 int variables then it can be done as:

int *p=(int *)malloc(n * 2) where n=10 & 2=sizeof(int)

int *p=(int *)calloc(10,2)

Q: What are macros? What are its advantages and disadvantages?

A: Macros are preprocessor directives. They get replaced in source code before compilation.Advantages are:

[*]We can replace any valid C statement or condition in user own words. We can do File inclusion also. We can do conditional compilation. We can pass arguments also in Macros. They can be used anywhere inside the program.

Disadvantages are:

[*]Macro will replace macro template with its macro expansion without checking any error. If there r number of occurrence of macros then it will increase the size of program.

Q: Difference between pass by reference and pass by value?

A: When we have argument as variable or any constant then function is termed as function pass by value. When we have address of variable as an argument in the function we call the function by reference.

Ex:

int x=27;

void func(x) à pass by value

void func(27) à pass by value

void func(&x) à pass by reference

Q: What is static identifier?

A: As explained above.

Q: Where are the auto variables stored?

A: They are stored in memory & default initial value is garbage value.

Q: Where does global, static, local, register variables, free memory and C Program instructions get stored?

A: Refer let us C.[/size]

 

Q: Difference between arrays and linked list?

A: Main difference is that array are static in nature. Once we declare it we can't modify its size. Also inserting or deleting elements in array is difficult. Array have fixed size that's why if at runtime, we want to increase or decrease its size, is not possible. While linked list are dynamic in nature they dynamically allocate memory for variables. Their size can be decided at runtime. Inserting & deleting element is also easy. One more difference is that searching a particular element is quite easy as it would use array index number while linked list will search the element from the start of list even thought the position of element is last. That's why traversing takes more time.

Q: What are enumerations?

A: An enumerated data type is user defined data type which provides a way for attaching name to numbers. Syntax is similar to structure. The enum keyword automatically enumerated the list of variables by assigning value 0,1,2,3….

 

enum shape{circle, square, rectangle)

here value of circle=0, square=1, rectangle=2

 

enum{red, green=7, blue=10};

here value of red=0, green=7, blue=10

 

We can't use float values in enum, only int values are allowed.

Q: Describe about storage allocation and scope of global, extern, static, local and register variables?

A: Refer let us C.

 

Q: What are register variables? What are the advantage of using register variables? A: A: Refer let us C.

 

Q: What is the use of typedef?

A: typedef keyword is used to rename the data type.

Ex: typedef int INTEGER;So instead of int a we have to use INTEGER a;

Q: Can we specify variable field width in a scanf() format string? If possible how?

A: As in following code:[/size]

void main()

{

float f;

printf("Enter value of f : ");

scanf("%3f",&f);

printf("f : %f",f);

}

 

If we enter f=12345.6789 it will give result as f=123

Q: Out of fgets() and gets() which function is safe to use and why?

A: gets() receives a string from the keyboard. More exactly, gets() gets a new line (\n) terminated string of characters from the keyboard and replaces the \n with \0;

Ex: char[10] s; gets(s);fgets() used to read a string from the file. fgets() takes three arguments. First is the address where the string is stored, second I the maximum length of the string which will prevent fgets() from reading in too long a string and overflowing the array. Third one is File pointer. If all lines from file have been read & we attempt to read one more line, in that case fgets() returns null. It also retains \n at the end of string & appends null byte to string to mark the end of string.

 

Syntax: fgets(char *s, int n, FILE *fp)That's why fgets() is more safer.

Q: Difference between strdup and strcpy?

A: strcpy() is defined in string.h copies one string into another.

Syntax: strcpy(char *destination, char * source);

Strdup() is also defined in string.h which will copy the string to newly created location. In strdup() makes a duplicate of source string , obtaining space with a call to malloc. Allocated space is (strlen(source string) +1) byte. Also we have to free this string when it is not used by calling free. That's why we have to add alloc.h while using strdup().

 

Ex: char *dupstr=strdup(char * sourcestr);

Q: What is recursion?

A: A function is called recursive if a statement within the body of a function calls the same function. It is the process of defining something in terms of itself.

Q: Differentiate between a for loop and a while loop? What are it uses?

A: Simple Question.

Q: What are the different storage classes in C?

A: auto, register, static & extern are different storage classes.

Q: Write down the equivalent pointer _expression for referring the same element a[j][k][l]?

A: *(*(*(*(a+i)+j)+k)+l)

 

Q: What is difference between Structure and Unions?

A: Declaration syntax is same foe both difference is that structure members have contiguous memory location while union members share common memory location having the size equal to variable size whose size is maximum than other variables.

Q: What the advantages of using Unions?

A: Unions are very useful while interacting with the hardware of the computer.

Q: What are the advantages of using pointers in a program?

A: Pointers will increase the execution speed. Using pointers we can acess array as they are correlated to each other. Also pointer can return more than one value from function. From called function we can change value of any variable of calling function using pointer.

Q: What is the difference between Strings and Arrays?

A: String is a character array. Array is defined as collection of similar data types under single variable name. They are also used as indexed variables as they r accessed by their indexes.So there is no difference between string & array. As string is another name for char array.

Q: In a header file whether functions are declared or defined?

A: Already explained.

 

Q: How structures are passed & return from the function?

A: Structures are user defined data types. So it is possible to pass structure as an argument or functions can return structures. Following example shows how structures are passed as an argument in function :

 

#include<stdio.h>

#include<conio.h>

 

void show(struct emp);

 

struct emp

{

int age;

char name[20];

float salary;

}

e1={21,"Himanshu",27000};

 

void main()

{

clrscr();

show(e1);

getch();

}

void show(struct emp e1)

{

printf("Age : %d \n",e1.age);

printf("Name : %s \n",e1.name);

printf("Salary : %f \n",e1.salary);

}

 

Following example show how functions return the structure:

 

#include<stdio.h>

#include<conio.h>

 

struct emp show();

 

struct emp{

int age;

char name[20];

float salary;

};

 

void main()

{

struct emp e1;

clrscr();

e1=show();

clrscr();

printf("Age : %d \n",e1.age);

printf("Name : %s \n",e1.name);

printf("Salary : %f \n",e1.salary);

getch();

}

 

struct emp show()

{

struct emp e1;

printf("Enter the age : ");

scanf("%d",&e1.age);

printf("Enter the name : ");

scanf("%s",e1.name);

printf("Enter the salary : ");

scanf("%f",&e1.salary);

return e1;}

 

Regards,

Himanshu B)

Share this post


Link to post
Share on other sites

Part 2:

 

Q: What is argc & argv?

A: Command Line Argument, argc stands for argument count & argv stands for argument vector. So, c for count & v for vector.

 

Q: How u will convert this binary digit 1101100100111100 to other system & which will be easier?

A:It is easy to convert binary number into octal number or hexadecimal number system. For conversion follow this number charts for octal & hexdecimal number.

 

To convert into octal number, group the numbers from right to left each consisting of 3 numbers. So for given example:

Binary Number: 1101100100111100

Grouping: 1 101 100 100 111 100

Well here the first digit is 1, so make it 001.

Grouping: 001 101 100 100 111 100

Octal conversion: 1 5 4 4 7 4

So Octal conversion for 1101100100111100 = 154474

 

Similarly for hexadecimal conversion, group the numbers from right to left each consisting of numbers. Then follow the table.

U will get as: 1101 1001 0011 1100

D 9 3 C

 

So hexadecimal conversion = D93C

Binary to Octal Table:

 

000 0

001 1

010 2

011 3

100 4

101 5

110 6

111 7

 

 

Binary to Hexadecimal Table:

 

0000 0

0001 1

0010 2

0011 3

0100 4

0101 5

0110 6

0111 7

1000 8

1001 9

1010 A

1011 B

1100 C

1101 D

1110 E

1111 F

 

Q: Which one is equivalent to multiplying by 2:Left shifting a number by 1 or Left shifting an unsigned int or char by 1?

A: Left shift will multiply the unsigned & int datatype. For char it will double the ascii value of character. E.g. left shift of A (ascii value=65) will give u character of acii value 130.

 

Q: Are command line args are local?

A: Command line arguments are local to main(). The explaination can be given as, by default program name is the first argument, therefore argc cannot be less than 1, by default it is1.

 

Though for different programs argc=1 by default, argv is different as explained earlier. So command line arguments are local to main().

 

Q: Do structure contains pointer to itself?

A: In linked list structure contain pointer to itself. Such pointers are called as self referential pointers.

e.g.

struct emp

{

int age;

struct emp *next;

};

Here struct emp *next is a pointer to structure itself & it points to next structure element.

 

Q: What is a far pointer? where we use it?

A: A far pointer is always is treated as a 32 bit pointer & contains both a segment & an offset address.The total memory (1 mb) I divided into a number of units each comprising 65536 (64 kb) locations. Each such unit is called as segment. Each segment always begins at a location number, which is exactly divisible by 16. The segment register contains the address were a segment begins, where as the offset register contains the offset of the data/code from where the segment begins.

e.g.

If segment register=2 & offset register=5 ten address of data/code is calculated as :

(16 * 2) + 5 = 32 + 5 = 37.

Declaration :

char *far=0xB0008000 here segment register=0xB000 & offset register=8

Generally we r using pointers are called as near pointers of 16 bits. Also 8088 b& 8086 chips (of the old PC & XT) operate only in real mode, and so can address only 1024 KB or 1MB memory. So if u want to use the memory beyond 64KB near pointers are not sufficient, to isolate this problem we have far & huge pointers.

Q: How will you declare an array of three function pointers where each function receives two ints and returns a float?

A: float ( * ( * arr_fptr[3])(int 1, int 2) )

Q: What is a NULL Pointer? Whether it is same as an uninitialized pointer?

A: For each pointer type ( like say a char pointer ) C defines a special pointer value that is guaranteed not to point to any object or function of that type. Usually the null pointer constant is used for representing a null pointer is the integer 0.Uninitialized pointer is not same as null pointer.

Q: What is a NULL Macro? What is the difference between a NULL Pointer and a NULL Macro?

A: A NULL macro is used to represent the null pointer in source code. It has a value 0 associated with it.A null pointer is a pointer, which doesn't point anywhere.The ASCII NUL character has all its bits as 0 but doesn't have any relationship with the null pointer.The null string is another name for empty string "".

Q: What does the error 'Null Pointer Assignment' mean and what causes this error?

A: The null assignment error is generated only in small & medium memory models which occurs when program changes the bottom of data segment. In Borland's C compiler, Borland places four zero bytes at the bottom of the data segment, follwed by Borland's copyright notice "Borland C++ - Copyright Intl.". In small memory models null pointer points to DS:0000. Thus assigning a value to the memory referenced by this pointer will overwrite the first zero byte in the data segment. At the program termination, the copyright banner & four zeroes are checked & if either has been modified, the null pointer assignment error is generated.

 

Q: Write a program for palindrome checking?

A: There r two approaches to solve this problem. First one using functions available in string.h (strrev() & strcmp()) & second one is without using it.

 

First approach by using strrev() & strcmp() from string.h :

 

#include<stdio.h>

#include<conio.h>

#include<string.h>

void main()

{

char *str1;

char *str2;

int x;

 

clrscr();

 

printf("Enter the string : ");

gets(str1);

str2=strrev(str1);

printf("Reverse String : %s \n",str2);

 

x=strcmp(str1,str2);

 

if(x==0)

printf("%s is palindrome \n",str1);

else

printf("%s is not palindrome \n",str1);

getch();

}

 

Second approach by using ASCII concept :

 

#include<stdio.h>

#include<conio.h>

 

void main()

{

char str1[20];

char str2[20];

int i,j;

int x,y;

 

clrscr();

 

printf("Enter the string : ");

 

gets(str1);

 

for(i=0;str1!='\0';i++);

 

i--;

 

for(j=0;i>=0;j++,i--)

 

str2[j]=str1;

 

str2[j]='\0';

 

printf("Reverse string : %s \n",str2);

 

for(i=0,j=0;str1!='\0';i++,j++)

{

x=str1;

y=str2[j];

if((x-y)!=0) break;

}

 

if(x==y)

printf("%s is palindrome \n",str1);

else

printf("%s is not palindrome \n",str1);

getch();

}

 

Q: How would you dynamically allocate a one-dimensional and two-dimensional array of integers?

A: Array elements have contiguous memory location. Similar holds true for two-dimensional array also. So there is no such arrangement that array elements are stored in row & column in memory. Therefore dynamic allocation for one-dimensional & two-dimensional array of integers is same. Example of dynamic allocation is in preceding question.

 

Q: How can you increase the size of a dynamically allocated array?

A:

 

#include<stdio.h>

#include<conio.h>

#include<alloc.h>

void main()

{

int i,n,*p;

 

clrscr();

 

printf("How many number of elements you want to enter? ");

scanf("%d",&n);

 

p=(int *)malloc(n*2);

 

if(p==NULL)

{

printf("Memory allocation unsuccessful");

exit();

}

 

for(i=0;i<n;i++)

{

printf("Enter the element %d : ",(i+1));

scanf("%d",(p+i));

}

 

printf("You had entered the follwing elements : \n");

 

for(i=0;i<n;i++)

 

printf("Element %d is %d \n",(i+1),*(p+i));

 

getch();

}

Q: How can you increase the size of a statically allocated array?

A: I think its impossible to increase the size of statically allocated memory. Otherwise we can use vector for static declaration which can grow or shrink in size as needed.

 

Q: When reallocating memory if any other pointers point into the same piece of memory do you have to readjust these other pointers or do they get readjusted automatically?

A: realloc() function used to move a particular block through n bytes. So we have to pass size of blcok & number of bytes. If block points to null it will work same as malloc() or calloc().

 

Q: Which function should be used to free the memory allocated by calloc()?

A: free() from malloc.h

 

Q: How much maximum can you allocate in a single call to malloc()?

A: Not more than 64KB in small & tiny memory models.

 

Q: How do you declare the following:

A: An array of three pointers to chars => char *arr[3]

 

An array of three char pointers => char *arr[3]

 

A pointer to array of three chars => char *p=&arr[3]

 

A pointer to function which receives an int pointer and returns a float pointer =>(float *)*funcptr(int *)

 

A pointer to a function which receives nothing and returns nothing => void (*funcptr)()

 

Q: Which header file should you include if you are to develop a function which can accept variable number of arguments?

A: We have to include stdarg.h to use va_arg(), va_list() & va_start().

 

Q: Which bit wise operator is suitable for putting on a particular bit in a number?

A: Bitwise AND operator is used to check whether a particular bit is ON or OFF. It is also used to turn OFF a particular bit in a number.

 

Q: Write a program to compare two strings without using the strcmp() function.

A:

 

#include<stdio.h>

#include<conio.h>

void main()

{

char *str1;

char *str2;

int x,i;

 

clrscr();

 

printf("Enter the first string : ");

 

gets(str1);

 

printf("Enter the second string : ");

 

gets(str2);

 

for(i=0;str1!='\0';i++)

{

x = str1 - str2;

 

if(x!=0)

break;

}

 

if(x==0)

printf("Strings are equal");

else

printf("Strings are not equal");

getch();

}

 

Q: How would you dynamically allocate a one-dimensional and two-dimensional array of integers?

A: Array elements have contiguous memory location. Similar holds true for two-dimensional array also. So there is no such arrangement that array elements are stored in row & column in memory. Therefore dynamic allocation for one-dimensional & two-dimensional array of integers is same. Example of dynamic allocation is in preceding question.

 

Q: How can you increase the size of a dynamically allocated array?

A:

#include<stdio.h>

#include<conio.h>

#include<alloc.h>

 

void main()

{

int i,n,*p;

 

clrscr();

 

printf("How many number of elements you want to enter? ");

scanf("%d",&n);

 

p=(int *)malloc(n*2);

 

if(p==NULL)

{

printf("Memory allocation unsuccessful");

exit();

}

 

for(i=0;i<n;i++)

{

printf("Enter the element %d : ",(i+1));

scanf("%d",(p+i));

}

 

printf("You had entered the follwing elements : \n");

for(i=0;i<n;i++)

printf("Element %d is %d \n",(i+1),*(p+i));

 

getch();

}

 

Q: How can you increase the size of a statically allocated array?

A: I think its impossible to increase the size of statically allocated memory. Otherwise we can use vector for static declaration which can grow or shrink in size as needed.

 

So these are the answers I knew. If anything wrong let me know. I am available on hik4uonly@yahoo.com or hkhatri27@gmail.com. Don't forget to put subject line, I got many like that in past.

 

All the best for job hunting.

 

Bbye...

 

Regards,

Himanshu B)

Ans.doc

Share this post


Link to post
Share on other sites

Hai frnds, This is malathi from b'lore can u mail all those ques and ans to my mail id vmalathi2008@gmail.com am waiting for ur mail,if possible java ques and ans also all the best to every one

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×