· Web viewWrite logic to find the highest consequite word in given string? Explain volitaile...

23
‘C’ INTERVIEW QUESTIONS 1) program for string reverse? Reverse a string in c without using temp String reverse using strrev in c programming language #include<stdio.h> #include<string.h> int main() { char str[50]; char *rev; printf("Enter any string : "); scanf("%s",str); rev = strrev(str); printf("Reverse string is : %s",rev); return 0; } String reverse in c without using strrev String reverse in c without using string function How to reverse a string in c without using reverse function #include<stdio.h> int main() { char str[50]; char rev[50]; int i=-1,j=0; printf("Enter any string : "); scanf("%s",str); while(str[++i]!='\0');

Transcript of · Web viewWrite logic to find the highest consequite word in given string? Explain volitaile...

Page 1: · Web viewWrite logic to find the highest consequite word in given string? Explain volitaile and const volatile? Difference b/w inline and macro? What is the difference b/w structure

‘C’ INTERVIEW QUESTIONS

1) program for string reverse?

Reverse a string in c without using tempString reverse using strrev in c programming language

#include<stdio.h> #include<string.h> int main() {    char str[50];    char *rev;    printf("Enter any string : ");    scanf("%s",str);    rev = strrev(str);    printf("Reverse string is : %s",rev);    return 0; }

String reverse in c without using strrevString reverse in c without using string functionHow to reverse a string in c without using reversefunction

#include<stdio.h> int main() {    char str[50];    char rev[50];    int i=-1,j=0;    printf("Enter any string : ");    scanf("%s",str);    while(str[++i]!='\0');    while(i>=0)    rev[j++] = str[--i];    rev[j]='\0';    printf("Reverse of string is : %s",rev);    return 0; }

Page 2: · Web viewWrite logic to find the highest consequite word in given string? Explain volitaile and const volatile? Difference b/w inline and macro? What is the difference b/w structure

Reverse a string in c using pointersC program to reverse a string using pointers

#include<stdio.h> int main() {    char str[50];    char rev[50];    char *sptr = str;

     char *rptr = rev;    int i=-1;    printf("Enter any string : ");    scanf("%s",str);    while(*sptr) {     sptr++;     i++;    }    while(i>=0) {     sptr--;     *rptr = *sptr;     rptr++;     --i;    }    *rptr='\0';     printf("Reverse of string is : %s",rev); return 0; }

Sample output:Enter any string : PointerReverse of string is : retnioP

2) diff between strlen and sizeof operators?sizeof is keyword of c which can find size of a string constant including null character but strlen is function which has been defined in a header file named string.h and can find number of characters in a string excluding null character. Most probably it is used to compare the size of string with some conditions. strlen() is used to get the length of an array of chars / string.

Page 3: · Web viewWrite logic to find the highest consequite word in given string? Explain volitaile and const volatile? Difference b/w inline and macro? What is the difference b/w structure

sizeof() is used to get the actual size of any type of data in bytes. Besides, sizeof() is a compile-time expression giving you the size of a type or a variable's type. It doesn't care about the value of the variable. strlen() is a function that takes a pointer to a character, and walks the memory from this character on, looking for a NULL character. It counts the number of characters before it finds the NULL character. In other words, it gives you the length of a C-style NULL-terminated string.Example:- #include<string.h> void main(){     int a,b;     a=strlen("itorian");     b=sizeof("itorian");     printf("%d  %d",a,b);     getch();}

3) Difference between i++ & ++i and Using of operator’s post & pre increment?

i++ is known as Post Increment whereas ++i is called Pre Increment.

1) i++ : i++ is post increment because it increments i's value by 1 after the operation is over.

Let’s see the following example:

int i = 1, j;

j = i++;

Here value of j = 1 but i = 2. Here value of i will be assigned to j first then i will be incremented.

2) ++i : ++i is pre increment because it increments i's value by 1 before the operation. It means j = i; will execute first and then i++.

Let’s see the following example:

int i = 1, j;

j = ++i;

Here value of j = 2 but i = 2. Here value of i will be assigned to j after the incrementation of i. Similarly ++i will be executed before j=i;.

For your question which should be used in the incrementation block of a for loop? the answer is, you can use any one.. no matter. It will execute your for loop same no. of times.

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

printf("%d ",i);

Page 4: · Web viewWrite logic to find the highest consequite word in given string? Explain volitaile and const volatile? Difference b/w inline and macro? What is the difference b/w structure

And

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

printf("%d ",i);

Both the loops will produce same output. ie 0 1 2 3 4.

It only matters where you are using it.

for(i = 0; i<5;)

printf("%d ",++i);

In this case output will be 1 2 3 4 5.

4) What is an Array..?

C Array is a collection of variables belongings to the same data type. You can store group of data of same data type in an array.

Array might be belonging to any of the data types

Array size must be a constant value.

Always, Contiguous (adjacent) memory locations are used to store array elements in memory.

It is a best practice to initialize an array to zero or null while declaring, if we don’t assign any values to array.

Example for C Arrays:

int a[10]; // integer array

char b[10]; // character array i.e. string

Types of C arrays:

There are 2 types of C arrays. They are,

Page 5: · Web viewWrite logic to find the highest consequite word in given string? Explain volitaile and const volatile? Difference b/w inline and macro? What is the difference b/w structure

One dimensional array

Multi dimensional array

Two dimensional array

Three dimensional array, four dimensional array etc…

1. One dimensional array in C:

Syntax : data-type arr_name[array_size];

Array declaration

Array initialization

Accessing array

Syntax:

data_type arr_name [arr_size]; data_type arr_name [arr_size]=

(value1, value2, value3,….); arr_name[index];

int age [5]; int age[5]={0, 1, 2, 3, 4, 5}; age[0];_/*0_is_accessed*/

age[1];_/*1_is_accessed*/

age[2];_/*2_is_accessed*/

char str[10]; char str[10]={‘H’,‘a’,‘i’}; (or)

char str[0] = ‘H’;

char str[1] = ‘a’;

char str[2] = ‘i; str[0];_/*H is accessed*/

str[1]; /*a is accessed*/

str[2]; /* i is accessed*/

Page 6: · Web viewWrite logic to find the highest consequite word in given string? Explain volitaile and const volatile? Difference b/w inline and macro? What is the difference b/w structure

Example program for one dimensional array in C:

#include<stdio.h>

int main()

{

int i;

int arr[5] = {10,20,30,40,50};

// declaring and Initializing array in C

//To initialize all array elements to 0, use int arr[5]={0};

/* Above array can be initialized as below also

arr[0] = 10;

arr[1] = 20;

arr[2] = 30;

arr[3] = 40;

arr[4] = 50; */

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

{

// Accessing each variable

printf(“value of arr[%d] is %d \n”, i, arr[i]);

}

}

Output:

value of arr[0] is 10

value of arr[1] is 20

value of arr[2] is 30

value of arr[3] is 40

value of arr[4] is 50

Page 7: · Web viewWrite logic to find the highest consequite word in given string? Explain volitaile and const volatile? Difference b/w inline and macro? What is the difference b/w structure

2. Two dimensional array in C:

Two dimensional array is nothing but array of array.

syntax : data_type array_name[num_of_rows][num_of_column]

S.no

Array declaration

Array initialization

Accessing array

1 Syntax:

data_type arr_name [num_of_rows][num_of_column]; data_type arr_name[2][2] = {{0,0},{0,1},{1,0},{1,1}}; arr_name[index];

2 Example:

int arr[2][2]; int arr[2][2] = {1,2, 3, 4}; arr [0] [0] = 1;

arr [0] ]1] = 2;

arr [1][0] = 3;

arr [1] [1] = 4;

Example program for two dimensional array in C:

#include<stdio.h>

int main()

{

int i,j;

// declaring and Initializing array

int arr[2][2] = {10,20,30,40};

/* Above array can be initialized as below also

Page 8: · Web viewWrite logic to find the highest consequite word in given string? Explain volitaile and const volatile? Difference b/w inline and macro? What is the difference b/w structure

arr[0][0] = 10; // Initializing array

arr[0][1] = 20;

arr[1][0] = 30;

arr[1][1] = 40; */

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

{

for (j=0;j<2;j++)

{

// Accessing variables

printf(“value of arr[%d] [%d] : %d\n”,i,j,arr[i][j]);

}

}

}

Output:

value of arr[0] [0] is 10

value of arr[0] [1] is 20

value of arr[1] [0] is 30

value of arr[1] [1] is 40

5) Explain storage classes in detail?

6) String reverse program?

7) Diff bet strlen and sizeof?

8) Why is sizeof called as operator insted of a function?

9) can u allocte memory dynamically for array of ten  integers?

10)what is little endian n big endian?and tell me the logic to finf out?

Page 9: · Web viewWrite logic to find the highest consequite word in given string? Explain volitaile and const volatile? Difference b/w inline and macro? What is the difference b/w structure

11)write a program to convert little endian to big endian?

12) if(printf("hello"))

{};

else

{

printf("world")}question is i want to output hello world what you will do?

13)Write logic to find the highest consequite word in given string?

14) Explain volitaile and const volatile?

15)Difference b/w inline and macro?

16)What is the difference b/w structure in c and structure in c++?

17) It’s possible to use the function inside the structure in c and c++?

18)Why we are using the function pointer what is the use of that?

19) Diff B’tn structure and union20) c programs on even and odd, strcpy, binary to decimal conversion and

they are asking some simple programs21) Compare pass by value, pass by reference and pass by address?22) Explain structure padding?23) Types of storage classes in C?24) Ranges of unsigned and signed integers?25) Difference btn #define and inline?26) write own strcpy function?27) Write a program to convert "Big endian int datatype" to "Little endian

int"?28) Check whether the given list is Palindrome or not? Note :  1 2 3 4 3 2 1 is

palindrome29) Write a function to Split the list in to Two halves with out using return type?30) How u change static variable value which is included in 1.c to change value

in 2.c without including it in header file?31) Execution steps of c program?

Page 10: · Web viewWrite logic to find the highest consequite word in given string? Explain volitaile and const volatile? Difference b/w inline and macro? What is the difference b/w structure

32) Write a c program to print hello world? Explain the flow in detail?33) Diff between structure and union?34) Define structure pointers?35) Different types of algorithms?36) Explain the logic for copying the block of memory from one to another using

the pointer?37) What is inline function? Explain with code? Whether the inline keyword is

added b4 the Declaration /definition?38) What is a macro? Explain with code? Why and wen go for macro?39) Diff b/w inline and macro?40) Consider a ptr “p”, when we do *p++; How compiler considers this

instruction Like (*p)++ or (*p++)?41) What is #define?42) What is the differnece between #define and constant?43) Give an example where we can use #define rather than constant.44)difference btn declaration and definition.?

45)can we intialize the variables in header file.?

46) can we declare the register variable as global.?

47) program for Fibonacci, prime48) without using strcat n strcpy funcations, write a program for the

particulars?49) Output for the following code a=5,b=6 c=a+b++?50) c=++a+b, output?51) allocate memory for 20 int using malloc?52) Validate the following code?

cahr, *ptr, str[]="hello";ptr++;ptr=t;printf("%s %s", p, str);

53) const char *p,char const *p,char *const p, what is the difference btn these?

54) what is dangling ptr?

Page 11: · Web viewWrite logic to find the highest consequite word in given string? Explain volitaile and const volatile? Difference b/w inline and macro? What is the difference b/w structure

55) what is the main usage of pointers?

56) explain about const and volatile in realtime scenario?

57) exlain about structures and unions,what are advantages of structures over unions and viceversa?

58) find the substring frm the given string,write the code and explain?

59) difference btn malloc and calloc, where exactly we use this, which scenario we use malloc and which scenario we use calloc,explain?

60) int *ptr=NULL,*ptr=100, this is TRUE or FALSE?

61) difference btn static and auto, explain with realtime example?

62) difference btn pointers and arrays?

63) explain about difference segments present in C?

64) string="mnpabcefghpnpcba",get the substring frm given string,find substring(mnp) frm the given and string, traverse(reverse) frm end of the string? 

65) explain about structure pointers?

66) difference btn enums,#define and typedef?

67) write code for array of 'n' function pointers  which takes char and returns ptr  which takes ptr and returns char?

68) Constant variables where they are used?

69) Can u define function inside a structure in c and c++?

70) Explain inline function?

71) What are the ways of pas sing aruments to a function?

72) What is null pointer?

Page 12: · Web viewWrite logic to find the highest consequite word in given string? Explain volitaile and const volatile? Difference b/w inline and macro? What is the difference b/w structure

73) what are the methods of dynamic memory allocation in c ?explain them?

74) macro for definition to find a greater number of two numbers?

75) macro with conditional operator to find greatest of three numbers?

76) macro vs typedef?

77) write a function to find a given number is prime number or not?

78) program to nibble swap using macro?

79) Write the program to find out the position of sub string in the given string , the string & substring is

given below :-

str1[]=”India is my country ”;

str2[]=”my”;

80) find the output :-

if address of 1st element of array is 4000;

int arr[]={1,2,3,4,5};

printf(“%u %u”, arr, &arr);

printf(“%u %u”, arr+1 ,&arr+1);

81) Find the output :-

if address of 1st element of array is 8000;

int arr[3][4]={1,2,3,4,5,6,7,8,9,10,11,12};

printf(“%u %u”,arr,arr+1);

printf(“%u “,&arr+1);

82) Write a Macro for setting the nth bit .

Page 13: · Web viewWrite logic to find the highest consequite word in given string? Explain volitaile and const volatile? Difference b/w inline and macro? What is the difference b/w structure

83) If register is not available then where the variable with storage class “register” will get stored.

84) Which data type can get stored in register . Can Float get stored in register.

85) What is the Volatile variable.

86) Write a program to count no. of ones.

87) Write a program for string reverse using pointer.

88) What is indirection operator .

89) Till what level pointer can be used( i.e ********p) ?

90) What is difference between i++ & i=i+1 ;

91) Write a program whether a string is palindrome or not and also optimized the code.

92) Declare a pointer to an array of functions.

93) What is Difference between structure & union .

94) Write a structure & initialize it & after that change the value of member variables.

95) What are access specifier in C.-> I confused access specifiers are in c++ , I told as I know access specifiers are in C++ & in C it is storage class.

96) Which types of library you have used in C & in your project.

97) Have you used pointers in your projects.

98) What is difference between include<stdlib.h> & include”stdlib.h” . Consider OS installed in c drive and also compiler in C drive .There are a no. of folders in c drive so how compiler search for .h file in c drive.

99) Difference between Const char *ptr and char*const*ptr1?100)Write a program to demonstrate factorial for given number using recursion?101) struct a

{        int a;        char b[3];

}what is the size of array ?

102)how to resolve structure padding problem in above code ?

Page 14: · Web viewWrite logic to find the highest consequite word in given string? Explain volitaile and const volatile? Difference b/w inline and macro? What is the difference b/w structure

103)use a structure and write a code to compare two dates ? eg : input is 12 - 4- 2011 and 13-3-2010, which is greater.

104) for the above question return 0 if two dates are equal, return 1 if date1 is greater than date2, and -1 if date1 is less than date2 ?

105) for the same question return the difference between two dates ?106)how to avoid preprocessor directives that are already declared in a file ?107)at what stage of compilation preprocessor directories are processed ?108)explain about dynamic memory allocation in c?109)difference btn malloc and calloc?110)Write program to multiplication of two numbers with out any syntax error?

111)what is return type of malloc,why u r doing type cast,what  it tells,112) If u allocate memory with malloc and u r doing it free what will happen,what

is exact meaning of memory leakage..113) If u allocate some bytes of memory with malloc in an application and if u r

not freeing it with free will the application works or will crash,If u exit the application will that memory still available or can i use that memory in other application…

114)How many memory segment are there in C?115)Write constant pointer to an integer?116)Write constant integer to pointer?117)What are the steps u will follow to implement while developing ur own printf

and scanf function?118)Where printf and scanf function will get memory?119)Where function parameter gets memory?120)What is function pointer and write syntax for function pointer?121)What is difference between enum and macro?122) size of empty structure123)give size of an data type with out using sizeof operator.124) in 1.c file int a is declared ["1.c"  int a;], 3.c file int a is declared ["3.c"  int

a;], 2.c file extern int a is declared ["2.c"  extern int a;] which file in  2.c file calls.

125)what is the procedure to convert .c file to .exe file.126)how to swap two integer in a variable by using bit wise operator .127)explain why pointers goes to 4 bytes when I say int *ptr;

Page 15: · Web viewWrite logic to find the highest consequite word in given string? Explain volitaile and const volatile? Difference b/w inline and macro? What is the difference b/w structure

128) struct Venkatesh{

Int data;Struct Venkatesh *ptr;

}Explain how the ptr will move as its an user defined datatype .

129) if I allocate memory and then free and after that I hold a value with pointer what happens?

130)explain why we do typecast while allocating memory in malloc?131)what happenes after I free memory in heap and then free(p) and then I say

p=20;132)can I say extern int i;with out definition in other file.133) How to declare the string in c?134) How to initialize the string?135) How to declare the string depending upon the user input string length?136) What is global and static in c?137) Did u used static and global variable in ur project?138) Char *S=”Novellus” if I print S and *S, what it will be the output?139) Char *S=”..................upto with 2000 character………….”; if I print S and *S,

what it will be the output and is it possible to print 2000charcter with this?140) Int main

{Char *S=” “;

}141) Is it initialize the string or not?142)what is size of char and unsigned char in terms of bits143)char x[]=”12345”; Copy this into string s144)unsingned int x=0x12; Write a prgm Convert this into integer145)he asked regarding about project how much u had used c++146)what is difference between pointer and auto pointer

147) printf("%d"); return type.

148) how to check the dynamiccaly allocated memory.

149) questions on 3dimensional array.150) input

Char str[]={“abc”, “aab”,”abb”, “acc”}

Page 16: · Web viewWrite logic to find the highest consequite word in given string? Explain volitaile and const volatile? Difference b/w inline and macro? What is the difference b/w structure

Char P[]=”abc”Output = {1, 0, 1, 0} need to compare both string if “abc” present in first string u should display as per the given output format.

151)What is realloc?152)What are the types of typecasting?153)What is reinterpret casting?154)Can u allocate memory for string by using malloc?155)write a program fibonacci series 0 1 1 2 3 5 8.......156)find sub matrix =[1 2] 3 4 5 6 7 8

                           1 2] 3 4 5 6 7 8                           3 4[1 2]  5 6 7 8                           3 4[1 2 ] 5 6 7 8                           1 2 3 4 5 6  [1 2]                           3 4 5 6 7 8  [1 2]

find [ 1 2]       [ 1 2] find the matrix157)diff between char a[7] and char *p;158) size of int in 32 bit complier and struct padding159) sizeof int in 16 bit complier and struct padding160)const int a=7. where it gets the memory.161) struct A

{char a;int b;char c;char *p;

}; what is the size of struct & why.162)can u find out the size of structure with out using sizeof() operator?163)can u find out the size of variable with out using sizeof() operator.164)can u declare a pointer to const char.165)can u declare a  const pointer to char type.166) int  a=5;

    char *p;          p=&a; it is compile or not.

167)what is NULL pointer.

Page 17: · Web viewWrite logic to find the highest consequite word in given string? Explain volitaile and const volatile? Difference b/w inline and macro? What is the difference b/w structure

168) int i=10,j=20,k;    K=i+++j;    Pf(“%d”,k); what is the output?169) int main()

{            char *p=NULL;            printf("%d\n",p+4);            return 0;

}170)Write a prog for prime number?171)Set the bit and reset the bit?172)write a prog for finding the set bit positions in a number?173)Given two matrices

1  23  4

                                         1 2 5 6 7 8 910                                         3 4 1 5 6 7 8 0                                         6 7 1 2 9 8 2 3                                         5 6 3 4 5 6 3 4                                         6 7 9 8 2 3 1 2                                           5 6 5 6 3 4 3 4              We hav to find that 1 2

3 4    matrix in which position?174) write a program to multiply 1 to 100 numbers?175)char const *p="hai";

          *p="j";           p="hi";   char *const p="string";            p="st";            *p="j";  tell me the output.

176)declare [5][10] two dimensional array,i want go to the location [2][7],can u write the logic by using pointer in single line.

177)char str1[]="srinivasarao";   char str2[]="is good";  i want to print the string "is srinivasarao good",can u write the program.

178) i want to delete one variable in structure?how?179) two pointers can acess only one variable?180)one pointer can acess two variables?

Page 18: · Web viewWrite logic to find the highest consequite word in given string? Explain volitaile and const volatile? Difference b/w inline and macro? What is the difference b/w structure

181) Explain the compilation process?182)where binary data will get stored?183)How to pass a two dimensional array to a function,just write prototype.184)Bitwise operator program.185) int main()

        {              char *a="abcde";              fun(a);              return 0;        }

   fun(char *p){

  p++;  pf("%s",p);

}186) int main()

  {    int x[10],y[10],i;      y=fun(x);

 for(i=0;i<=10;i++){ printf("%d",y[i]);}}int * fun(int a[]){

  int i;a[0]=0;a[1]=1;for(i=2;i<=10;i++) {

  a[i]=i;}return a;

Page 19: · Web viewWrite logic to find the highest consequite word in given string? Explain volitaile and const volatile? Difference b/w inline and macro? What is the difference b/w structure

}what is the output of above 2 programs:

187) Int p=0xABCD;  int i=2*(*p);  pf("i");  delay(100);  i=2*(*p);  pf("i");

    Initially content of address 0xABCD is "0" after every 100seconds that content will be incremented by 1.wt ll be the output188) If a fn is called recursively infinitely. what will happen?189) rotate a string from left  infinitely.

       eg: Hello             elloH             lloHe              -----              -----

190)Sort an interger array using recursive function.191)create a mirror image of an n*n array. check whether the mirror image and

original array are same.192)we have 10*10 matrix check weather original image and mirror image are

equal or not193)by using recussive function sorting of integer array194)What are static and dynamic libraries?195) Write prog for convert string 1234 to integer 1234?196) Pgm to demonstrate call by value & call by reference?197) in a string "REBACA" how to print each character is printed how many times198)write the program or algorithm to find the 2nd largest number in an array

using data stuctures or general program199)how to communicate one internet application with c program file?200) A=3.b=5,c=6 I want result r=356 using bitwise operators?201) Add two very large numbers (we can not use int or long int) larger than

long int..202) swap high value and low value( with 16 bit)203) write a program to compare strings with pointers(we should not use

predefined functions i.e. strcmp

Page 20: · Web viewWrite logic to find the highest consequite word in given string? Explain volitaile and const volatile? Difference b/w inline and macro? What is the difference b/w structure

204) write a c program reverse the numbers 1-25 and replace some numbers as ?,#,%

205) prime number series program206) const int i;

Static int i; How we are changing the i values in both cases207) int  fun(int,int) char fun(int,int) int fun(char,char) char fun(char,char);

is it work,why compiler not check return type208) What is self-referential structure?209) Can I use delete in c?