Materials from Interview Mantra. Subscribe to free updates by way of electronic mail. Materials from Interview Mantra. Subscribe to free updates by way of electronic mail. Favorite 50 – C Interview Question Bank for freshers and skilled IT programmers Written by Madhulika Reddy and Dhoka Ratan. Edited and Printed by Sridhar Jammalamadaka Get the newest updates and information on subjects Profession and Schooling from Interview Mantra – Subscribe to Interview Mantra at no cost. ABOUT THIS BOOK This guide contains of Interview Questions and Solutions collected from the well-known profession recommendation weblog www. InterviewMantra. et The goal of this guide is to Help freshers and skilled programmers to rapidly brush up the essential ideas of C language. This guide can be utilized as a fast examine information earlier than attending a job interview which requires information of C programming language. The questions that seem on this guide are few of essentially the most ceaselessly requested questions in IT Job interviews in prime MNC firms. All of the questions have been neatly answered and have been supported with instance code wherever relevant. A variety of effort has been put into this guide to make the solutions as correct as potential, however no guarantee or health is implied.
The authors and the writer shall have neither legal responsibility nor duty to any individual or entity with respect to any loss or damages arising from the data contained on this guide or from the usage of the packages accompanying it. Please ship your suggestions to us by way of electronic mail to [email protected] internet COPYRIGHT INFO C language – Interview Question Bank by Sridhar Jammalamadaka is licensed beneath a Inventive Commons Attribution-Share Alike 2. 5 India License. Primarily based on a piece at www. interviewmantra. internet. In easy phrases, you might use this work for industrial functions, remix the work, reproduce it by any means, offered ou preserve a hyperlink to http://www. interviewmantra. internet and attribute the work to the proprietor – Sridhar Jammalamadaka. CONTENTS AT A GLANCE 1. 2. three. four. 5. Chapter Identify pg-no Variables & Management Move . . . . . . . . . . . . . . . . . . . . 6 Operators, Constants & Buildings . . . . . . . . . . . .11 Features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .17 Pointers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23 Packages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .29 Materials from Interview Mantra. Subscribe to free updates by way of electronic mail. TABLE OF CONTENTS
CHAPTER 1: Variables & Management Move 1. What’s the distinction between declaring a variable and defining a variable? 2. What’s a static variable? three. What’s a register variable? four. The place is an auto variable saved? 5. What’s scope & storage allocation of extern and international variables? 6. What’s scope & storage allocation of register, static and native variables? 7. What are storage reminiscence, default worth, scope and lifetime of Automated and Register storage class? eight. What are storage reminiscence, default worth, scope and lifetime of Static and Exterior storage class? 9. What’s the distinction between ‘break’ and ‘proceed’ statements? zero. What’s the distinction between ‘for’ and ‘whereas’ loops? CHAPTER 2: Operators, Constants & Buildings 1. Which bitwise operator is appropriate for checking whether or not a specific bit is ON or OFF? 2. Which bitwise operator is appropriate for turning OFF a specific bit in a quantity? three. What’s equal of multiplying an unsigned int by 2: left shift of quantity by 1 or proper shift of quantity by 1? four. What’s an Enumeration Fixed? 5. What’s a construction? 6. What are the variations between a construction and a union? 7. What are some great benefits of unions? eight. How can typedef be to outline a kind of construction? 9.

Write a program that returns three numbers from a perform utilizing a construction. 10. In code snippet under: struct Date int yr; int day; int month; date1,date2; date1. yr = 2004; date1. day = four; date1. month = 12; Write a perform that assigns values to date2. Arguments to the perform have to be tips to the construction, Date and integer variables date, month, yr. Materials from Interview Mantra. Subscribe to free updates by way of electronic mail. CHAPTER three: Features 1. What’s the goal of major() perform? 2. Clarify command line arguments of major perform? three. What are header recordsdata? Are features declared or outlined in header recordsdata ? four.
What are the variations between formal arguments and precise arguments of a perform? 5. What’s go by worth in features? 6. What’s go by reference in features? 7. What are the variations between getchar() and scanf() features for studying strings? eight. Out of the features fgets() and will get(), which one is safer to make use of and why? 9. What’s the distinction between the features strdup() and strcpy()? CHAPTER four: Pointers 1. What’s a pointer in C? 2. What are some great benefits of utilizing pointers? three. What are the variations between malloc() and calloc()? four. Find out how to use realloc() to dynamically improve dimension of an already allotted array? . What’s the equal pointer expression for referring a component a[i][j][k][l], in a 4 dimensional array? 6. Declare an array of three perform pointers the place every perform receives two integers and returns float. 7. Clarify the variable project within the declaration int *(*p[10])(char *, char *); eight. What’s the worth of sizeof(a) /sizeof(char *) in a code snippet: char *a[4]=; 9. (i) What are the variations between the C statements under: char *str = “Howdy”; char arr[] = “Howdy”; (ii) Whether or not following statements get complied or not?
Clarify every assertion. arr++; *(arr + 1) = ‘s’; printf(“%s”,arr); CHAPTER 5: Packages 1. Write a program to search out factorial of the given quantity. 2. Write a program to examine whether or not the given quantity is even or odd. three. Write a program to swap two numbers utilizing a short lived variable. four. Write a program to swap two numbers with out utilizing a short lived variable. Materials from Interview Mantra. Subscribe to free updates by way of electronic mail. 5. Write a program to swap two numbers utilizing bitwise operators. 6. Write a program to search out the best of three numbers. 7. Write a program to search out the best amongst ten numbers. . Write a program to examine whether or not the given quantity is a primary. 9. Write a program to examine whether or not the given quantity is a palindromic quantity. 10. Write a program to examine whether or not the given string is a palindrome. 11. Write a program to generate the Fibonacci collection. 12. Write a program to print “Howdy World” with out utilizing semicolon anyplace within the code. 13. Write a program to print a semicolon with out utilizing a semicolon anyplace within the code. 14. Write a program to match two strings with out utilizing strcmp() perform. 15. Write a program to concatenate two strings with out utilizing strcat() perform. 16.
Write a program to delete a specified line from a textual content file. 17. Write a program to switch a specified line in a textual content file. 18. Write a program to search out the variety of traces in a textual content file. 19. Write a C program which asks the person for a quantity between 1 to 9 and reveals the quantity. If the person inputs a quantity out of the required vary, this system ought to present an error and immediate the person for a legitimate enter. 20. Write a program to show the multiplication desk of a given quantity. Testimonials Anushka M says “Thanks soooo a lot for all these questions, together with the options. It’s an amazing compilation.
Thanks loads guys. 🙂 ” Nameless says “Superior. Thanks a ton for importing this pdf, your idea was crystal clear. Now I’m very assured about myself. Now I am able to face the interview problem. Thanks as soon as once more. ” Urmi says “Thank You.. It is Good.. It saved my priceless Time.. Thanks loads! ” Rajakumari says “Thanks so … a lot Mr. Sridhar. No phrases to say , lot of thanks…… Very helpful to freshers & skilled. ” Materials from Interview Mantra. Subscribe to free updates by way of electronic mail. CHAPTER 1: Variables & Management Move 1. What’s the distinction between declaring a variable and defining a variable?
Declaration of a variable in C hints the compiler concerning the kind and dimension of the variable in compile time. Equally, declaration of a perform hints about kind and dimension of perform parameters. No area is reserved in reminiscence for any variable in case of declaration. Instance: int a; Right here variable ‘a’ is asserted of information kind ‘int’ Defining a variable means declaring it and in addition allocating area to carry it. We are able to say “Definition = Declaration + House reservation”. Instance: int a = 10; Right here variable “a” is described as an int to the compiler and reminiscence is allotted to carry worth 10. 2. What’s a static variable?
A static variable is a particular variable that’s saved within the information section in contrast to the default computerized variable that’s saved in stack. A static variable could be initialized by utilizing key phrase static earlier than variable identify. Instance: static int a = 5; A static variable behaves in a distinct method relying upon whether or not it’s a international variable or an area variable. A static international variable is identical as an odd international variable besides that it can’t be accessed by different recordsdata in the identical program / challenge even with the usage of key phrase extern. A static native variable is completely different from native variable.
It’s initialized solely as soon as irrespective of what number of occasions that perform by which it resides is known as. It could be used as a rely variable. Instance: #embody //program in file f1. c void rely(void) static int count1 = zero; int count2 = zero; count1++; count2++; printf(“Worth of count1 is %d, Worth of count2 is %d”, count1, count2); /*Primary perform*/ int major() rely(); rely(); rely(); return zero; Output: Worth of count1 is 1, Worth of count2 is 1 Worth of count1 is 2, Worth of count2 is 1 Materials from Interview Mantra. Subscribe to free updates by way of electronic mail. Worth of count1 is three, Worth of count2 is 1 three. What’s a register variable?
Register variables are saved within the CPU registers. Its default worth is a rubbish worth. Scope of a register variable is native to the block by which it’s outlined. Lifetime is until management stays inside the block by which the register variable is outlined. Variable saved in a CPU register can at all times be accessed quicker than the one that’s saved in reminiscence. Due to this fact, if a variable is used at many locations in a program, it’s higher to declare its storage class as register Instance: register int x=5; Variables for loop counters could be declared as register. Notice that register key phrase could also be ignored by some compilers. . The place is an auto variables saved? Primary reminiscence and CPU registers are the 2 reminiscence areas the place auto variables are saved. Auto variables are outlined beneath computerized storage class. They’re saved in major reminiscence. Reminiscence is allotted to an computerized variable when the block which comprises it’s referred to as and it’s de-allocated on the completion of its block execution. Auto variables: Storage : major reminiscence. Default worth : rubbish worth. Scope : native to the block by which the variable is outlined. Lifetime : until the management stays inside the block by which the variable is outlined. 5.
What’s scope & storage allocation of extern and international variables? Extern variables: belong to the Exterior storage class and are saved in the principle reminiscence. extern is used when we now have to refer a perform or variable that’s applied in different file in the identical challenge. The scope of the extern variables is World. Instance: /*************** Index: f1. c ****************/ #embody extern int x; int major() printf(“worth of x %d”, x); return zero; Index: f2. c ****************/ int x = three; Right here, this system written in file f1. c has the principle perform and reference to variable x. The file f2. c has the declaration of variable x.
The compiler ought to know the datatype of x and that is accomplished by extern definition. Materials from Interview Mantra. Subscribe to free updates by way of electronic mail. World variables: are variables that are declared above the principle( ) perform. These variables are accessible all through this system. They are often accessed by all of the features in this system. Their default worth is zero. Instance: #embody int x = zero; /* Variable x is a world variable. It may be accessed all through this system */ void increment(void) x = x + 1; printf(” worth of x: %d”, x); int major() printf(” worth of x: %d”, x); increment(); return zero; 6.
What’s scope & storage allocation of register, static and native variables? Register variables: belong to the register storage class and are saved within the CPU registers. The scope of the register variables is native to the block by which the variables are outlined. The variables that are used for extra variety of occasions in a program are declared as register variables for quicker entry. Instance: loop counter variables. register int y=6; Static variables: Reminiscence is allotted firstly of this system execution and it’s reallocated solely after this system terminates.
The scope of the static variables is native to the block by which the variables are outlined. Instance: #embody void decrement() static int a=5; a–; printf(“Worth of a:%d”, a); int major() Right here ‘a’ is initialized solely as soon as. Each time this perform is known as, ‘a’ doesn’t get initialized. so output can be four three 2 and many others. , Native variables: are variables that are declared inside any perform or a block. They are often accessed solely by perform or block by which they’re declared. Their default worth is a rubbish worth. 7. What are storage reminiscence, default worth, scope and lifetime of Automated and Register storage class? . Automated storage class: Storage : Default worth : major reminiscence. rubbish worth. Materials from Interview Mantra. Subscribe to free updates by way of electronic mail. Scope Lifetime Storage Default worth Scope Lifetime : : : : : : native to the block by which the variable is outlined. until management stays inside the block. CPU registers. rubbish worth. native to the block by which the variable is outlined. until management stays inside the block. 2. Register storage class: eight. What are storage reminiscence, default worth, scope and lifetime of Static and Exterior storage class? 1. Static storage class: Storage Default worth Scope
Lifetime Storage Default worth Scope Lifetime : : : : : : : : major reminiscence. zero native to the block by which the variable is outlined. until the worth of the variable persists between completely different perform calls. major reminiscence zero international so long as this system execution would not come to an finish. 2. Exterior storage class: 9. What’s the distinction between ‘break’ and ‘proceed’ statements? Variations between ‘break’ and ‘proceed’ statements break 1. break is a key phrase used to terminate the loop or exit from the block. The management jumps to subsequent assertion after the loop or block. 2. Syntax: Assertion 1; Assertion 2; Assertion n; break; three. reak can be utilized with for, whereas, do- whereas, and change statements. When break is utilized in nested loops i. e. inside the inside most loop then solely the innermost loop is terminated. four. Instance: i = 1, j = zero; whereas(i a && b ; c) printf(“b is Larger than a and c”); else if (c ; a && c ; b) else return zero; } Output: Enter a,b,c: three 5 eight c is Larger than a and b Clarification with examples: Think about three numbers a=5,b=four,c=eight if(a;b && a;c) then a is larger than b and c now examine this situation for the three numbers 5,four,eight i. . if(5;four && 5;eight) /* 5>four is true however 5>eight fails */ so the management shifts to else if situation else if(b;a && b;c) then b is larger than a and c now checking this situation for five,four,eight i. e. else if(four;5 && four;eight) /* each the circumstances fail */ now the management shifts to the subsequent else if situation else if(c;a && c;b) then c is larger than a and b Materials from Interview Mantra. Subscribe to free updates by way of electronic mail. now checking this situation for five,four,eight i. e. else if(eight;5 && eight;four) /* each circumstances are glad */ Thus c is larger than a and b. 7.
Write a program to search out the best amongst ten numbers. Program: #embody int major() Output: Enter ten values: 2 53 65 three 88 eight 14 5 77 64 Best of ten numbers is 88 Clarification with instance: Entered values are 2, 53, 65, three, 88, eight, 14, 5, 77, 64 They’re saved in an array of dimension 10. et a[] be an array holding these values. /* how the best amongst ten numbers is discovered */ Allow us to think about a variable ‘best’. Originally of the loop, variable ‘best’ is assinged with the worth of first ingredient within the array best=a[0]. Right here variable ‘best’ is assigned 2 as a[0]=2. Under loop is executed till finish of the array ‘a[]’;. for(i=zero; igreatest) } For every worth of ‘i’, worth of a[i] is in contrast with worth of variable ‘best’. If any worth higher than the worth of ‘best’ is encountered, it will get replaced by a[i].
After completion of ‘for’ loop, the worth of variable ‘best’ holds the best quantity within the array. On this case 88 is the best of all of the numbers. Materials from Interview Mantra. Subscribe to free updates by way of electronic mail. eight. Write a program to examine whether or not the given quantity is a primary. A first-rate quantity is a pure quantity that has just one and itself as elements. Examples: 2, three, 13 are prime numbers. Program: #embody major() { int n, i, c = zero; printf(“Enter any quantity n: “); scanf(“%d”, ); /*logic*/ for (i = 1; i

Published by
Write
View all posts