{"id":84822,"date":"2021-10-04T09:00:34","date_gmt":"2021-10-04T03:30:34","guid":{"rendered":"https:\/\/techvidvan.com\/tutorials\/?p=84822"},"modified":"2021-10-04T09:00:34","modified_gmt":"2021-10-04T03:30:34","slug":"c-interview-questions","status":"publish","type":"post","link":"https:\/\/techvidvan.com\/tutorials\/c-interview-questions\/","title":{"rendered":"C Interview Questions"},"content":{"rendered":"<p>The C programming language is the base for all programming languages. C is one of the oldest and still most used programming languages. It is simple to understand and it supports fast compilation. C was developed to create UNIX operating systems. Today, the UNIX operating system is the most used network operating system all over the world.<\/p>\n<p>In this tutorial, we showed some important and trending interview questions of the C programming language. These questions are based on different types of concepts in C. It will help you in getting placed at big companies such as TCS, Infosys, Wipro, Accenture etc.<\/p>\n<h3>C Interview Questions and answers<\/h3>\n<p>These interview questions will help you to understand the basic concepts of the C programming language.<\/p>\n<p><strong>Q.1 State the difference between typedef and #define.<\/strong><\/p>\n<p><strong>Ans.<\/strong> With the help of<strong> typedef keyword<\/strong>, you can give alternative names to the existing data type. With this, you cannot create a new data type. It is mainly used in structures, unions etc. to reduce the complexity of the program code.<\/p>\n<p><strong>Syntax of typedef:-<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">typedef data_type name_of_new_data_type;\n<\/pre>\n<p><strong>Example:-<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">typedef unsigned int new_int;\n<\/pre>\n<p><strong>#define<\/strong> is a preprocessor directive. The main purpose of this is to replace the value before compilation. It gives an alias name for the defined macro.<\/p>\n<p><strong>Syntax of #define:-<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">#define NAME value\n<\/pre>\n<p><strong>Example:-<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">#define SIZE 7\n<\/pre>\n<p><strong>Q.2 Tell the difference between long and double data types.<\/strong><\/p>\n<p><strong>Ans.<\/strong> These both data types have similar purposes but they are different. For storing large integer values, you can use the long data type. And for storing floating point values which have higher precision than float, you can use a double data type.<\/p>\n<p><strong>long data type<\/strong><br \/>\nSuppose, a programmer wants to use large numbers on their code then they can use the type specifier named <strong>long.<\/strong><\/p>\n<p><strong>Syntax of long:-<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">long j; \/\/ for storing integer values\nlong long o; \/\/ for storing integer values\nlong double p; \/\/ for storing floating point values\n<\/pre>\n<p><strong>double data type<\/strong><\/p>\n<p>The main purpose of this is to store decimal numbers with double precision.<br \/>\nThe difference between <strong>float<\/strong> and <strong>double<\/strong> is that the size of <strong>float<\/strong> is 4 bytes and the size of <strong>double<\/strong> is 8 bytes.<\/p>\n<p><strong>Syntax of double:-<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">double a;\n<\/pre>\n<p><strong>Q.3 Why should you use macros over functions?<\/strong><\/p>\n<p><strong>Ans.<\/strong> One big advantage of using macros over functions is that macros are preprocessed. Unlike functions, Macros are processed before the compilation of a program. Functions are not preprocessed. They are simply compiled.<\/p>\n<p><strong>Macros in C<\/strong><\/p>\n<p>You can say that macro is a piece of code that is replaced by the value of the macro throughout the program. You can define a macro with <strong>#define<\/strong> directive. At the end of defining a macro, you don\u2019t have to put a semicolon(;) to terminate it.<\/p>\n<p><strong>Example:-<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">#include &lt;stdio.h&gt;\n#define SIDE 4\nint main() {\n  int area;\n  area = SIDE*SIDE;\n  printf(\"Area is: %d\",area);\n  return 0;\n}\n<\/pre>\n<p><strong>Output:-<\/strong><br \/>\nArea is: 16<\/p>\n<p><strong>Functions in C<\/strong><\/p>\n<p>Functions are very useful for all the programming languages. With the help of functions, you can divide a large block of code into small blocks of code and you can also execute those blocks of code again and again. It will save your precious time.<\/p>\n<p><strong>E<\/strong><strong>xample:-<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">int sum(int n1, int n2){\nint final;\nfinal = n1 + n2;\nreturn final;\n}\n<\/pre>\n<p><strong>Q.4 What is the output of the following program?<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">#include &lt;stdio.h&gt;\nint main(void)\n{\nint data;\nint  val= 1;\nint arr[4] = { 2, 3, 1, 4};\ndata = 4 * 4 + arr[val++] - (9 \/ val);\nprintf(\"%d\", data);\nreturn 0;\n}\n<\/pre>\n<p><strong>Ans.<\/strong> 15<\/p>\n<p><strong>Q.5 Can you give arguments to the main() function?<\/strong><\/p>\n<p><strong>Ans.<\/strong> Yes, you can give command line arguments to the main function. You can only pass two arguments to the main function which are <strong>argc<\/strong> and <strong>argv.<\/strong><\/p>\n<p><strong>Example:-<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">#include &lt;stdio.h&gt;\n\nint main(int argc, char *argv[])\n{\nfor(int i=1; i&lt;argc; i++)\nprintf(\"%s \", argv[i]);\nprintf(\"\\n\");\nreturn 0;\n}\n<\/pre>\n<p>If you give an argument such as \u201cHave a nice day\u201d from the terminal then it will print you the below output.<\/p>\n<p><strong>Output:-<\/strong><br \/>\nHave a nice day<\/p>\n<p><strong>Q.6 What is the Difference between local and global variables in C.<\/strong><\/p>\n<p><strong>Ans.<\/strong><\/p>\n<table>\n<tbody>\n<tr>\n<td><b>Local Variable in C<\/b><\/td>\n<td><b>Global Variable in C<\/b><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">Local variables are declared inside the main function.<\/span><\/td>\n<td><span style=\"font-weight: 400\">Global variables are declared outside the main function.\u00a0<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">Declared only for the main function.<\/span><\/td>\n<td><span style=\"font-weight: 400\">Declared for the entire code.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">These are stored in a stack unless specified.<\/span><\/td>\n<td><span style=\"font-weight: 400\">For global variables, the compiler decides the storage location.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">Only be accessible from inside of the main function.<\/span><\/td>\n<td><span style=\"font-weight: 400\">Only accessible from inside and from outside of the main function.<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><strong>Q.7 Why C is known as the base for all programming languages?<\/strong><\/p>\n<p><strong>Ans.<\/strong> Using the C programming language, several compilers and JVM\u2019s are written. Many programming languages have borrowed the syntax and semantics of C like Python, Java, Rust etc. The C programming language gave birth to new concepts such as array, file handling, pointers, functions etc which are used by these languages also.<\/p>\n<p><strong>Q.8<\/strong> What is the use of printf() and scanf() functions in C?<\/p>\n<p><strong>Ans.<\/strong> The main purpose of this function is to display the output on the screen.<br \/>\nBelow are the format specifiers which you can use in the printf() function.<\/p>\n<ul>\n<li><strong>%d:<\/strong> Used to print an integer value.<\/li>\n<li><strong>%s:<\/strong> Used to print a string.<\/li>\n<li><strong>%c:<\/strong> Used to display a character value.<\/li>\n<li><strong>%f:<\/strong> Used to display a floating point value.<\/li>\n<\/ul>\n<p>With the help of the <strong>scanf()<\/strong> function, you can take input from the user.<\/p>\n<p><strong>Q.9<\/strong> Why to use static variables in C?<br \/>\n<strong>Ans.<\/strong><\/p>\n<ul>\n<li>A variable, defined as static, is known as a static variable. If a variable is set to static then the value of that variable does not change between multiple function calls.<\/li>\n<li>You can use it as a common value which you can share with all the methods.<\/li>\n<li>You can initialize the static variable only once.<\/li>\n<li>Mainly the static variable is initialized to zero. It will change if you update the value of that static variable.<\/li>\n<\/ul>\n<p><strong>Q.10<\/strong> Why to use functions in C?<br \/>\n<strong>Ans.<\/strong><\/p>\n<ul>\n<li>You can make use of functions to execute the same block of code again and again.<\/li>\n<li>You can call a function several times from anywhere in the program code.<\/li>\n<li>With the help of functions, you can break a big program into smaller programs. In this way, the program code will be more understandable.<\/li>\n<\/ul>\n<p><strong>Q.11<\/strong> What is the output of the following program?<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">#include &lt;stdio.h&gt;\nint main()\n{\nint x, y = 3;\nfunc(&amp;x,&amp;y);\nprintf(\"%d%d\",x,y);\nreturn 0;\n}\nvoid func(int *x , int*y)\n{\n*x = *x * *y;\n*y = *y * *y;\n}\n<\/pre>\n<p><strong>Ans.<\/strong> 09<\/p>\n<p><strong>Q.12<\/strong> What is dynamic memory allocation?<br \/>\n<strong>Ans.<\/strong><\/p>\n<ul>\n<li>In dynamic memory allocation, the memory is allocated at runtime and you can increase it during executing the program.<\/li>\n<li>You can use malloc() and calloc() functions to allocate memory at runtime.<\/li>\n<li>You don\u2019t have to use dynamic pointers to access the memory.<\/li>\n<li>It provides less memory space to store the variable.<\/li>\n<\/ul>\n<p><strong>Example:-<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">int *point= malloc(sizeof(int)*5); \n\n<\/pre>\n<p><strong>Q.13<\/strong> Can you compile a program without the main() function?<\/p>\n<p><strong>Ans.<\/strong> Yes, you can compile a program without the main() function but that program cannot be executed. If you want to run and compile a program without the main() function then you can make use of <strong>#define.<\/strong><\/p>\n<p><strong>Example:-<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">#include&lt;stdio.h&gt;    \n#define start main    \nvoid start() {    \n   printf(\"Have a nice day!\");   \n} \n<\/pre>\n<p><strong>Q.14<\/strong> What is the output of the following program?<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">#include \"stdio.h\"\nint fun(int num)\n{\nprintf(\"%d\",num);\nreturn 0;\n}\nint main()\n{\nfun;\nreturn 0;\n}\n<\/pre>\n<p><strong>Ans.<\/strong> This program won\u2019t throw you an error. But the fun() function won\u2019t get executed. So, the program will print nothing.<\/p>\n<p><strong>Syntax:-<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">(type_name) expression; \n<\/pre>\n<p><strong>Q.15<\/strong> Write a program to check if the number is an Armstrong number or not.<\/p>\n<p><strong>Ans.<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">#include&lt;stdio.h&gt; \t \n#include&lt;conio.h&gt; \t \nint main() \t \n{ \t \nint num=155,rev,sum=0,tmp;\ntmp=num; \t \nwhile(num&gt;0) \t \n{ \t \nrev=num%10; \t \nsum=sum+(rev*rev*rev); \t \nnum=num\/10; \t \n} \t \nif(tmp==sum) \t \nprintf(\"It is an armstrong number!\"); \t \nelse \t \nprintf(\"It is not an armstrong number!\"); \t \ngetch();  \n}\n<\/pre>\n<p><strong>Output:-<\/strong><br \/>\nIt is not an armstrong number!<\/p>\n<h3>Intermediate C Programming Interview Questions<\/h3>\n<p><strong>Q.16<\/strong> Write a program to reverse a number in C?<\/p>\n<p><strong>Ans.<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">#include&lt;stdio.h&gt;  \nint main()    \n{    \nint number=265, rev=0, remainer;    \nwhile(number!=0)    \n{    \nremainer=number%10;    \nrev=rev*10+remainer;    \nnumber\/=10;    \n}    \nprintf(\"%d\",rev);    \nreturn 0;  \n}\n<\/pre>\n<p><strong>Output:-<\/strong><br \/>\n562<\/p>\n<p><strong>Q.17<\/strong> What is the output of the following program?<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">#include&lt;stdio.h&gt;\n#include&lt;stdlib.h&gt;\nint main()\n{\nint x=25,y=65,res;\nint i;\nfor(i = 1; i &lt;= x &amp;&amp; i &lt;= y; i++)\n{\nif((x % i == 0) &amp;&amp; (y % i == 0))\n{\nres = i;\n}\n}\nprintf(\"%d\",res);\nreturn 0;\n}\n<\/pre>\n<p><strong>Ans.<\/strong> 5<\/p>\n<p><strong>Q.18<\/strong> Why should you use the sprintf() function in C?<\/p>\n<p><strong>Ans.<\/strong> The sprintf() function stands for string print. You cannot display the output on the screen using this function. It helps you to transfer the data into the buffer.<\/p>\n<p><strong>Syntax:-<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">int sprintf ( char *string, const char *name, ... ); \n<\/pre>\n<p><strong>Example:-<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">#include&lt;stdio.h&gt;  \nint main()  \n{  \nchar string[20];  \nint s1=sprintf(string,\"TechVidvan\");  \nprintf(\"Value of s1: %d\",s1);  \nreturn 0;\n}\n<\/pre>\n<p><strong>Q.19<\/strong> Why does n + + execute faster than the n+1?<\/p>\n<p><strong>Ans.<\/strong> n++ needs only one variable. It is a unary operator. n+1 is a binary operation that adds overhead to take more time. In modern compilers, the execution of time of both n++ and n+1 are equivalent.<\/p>\n<p><strong>Example:-<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">#include&lt;stdio.h&gt;\n#include&lt;stdlib.h&gt;\nint main()\n{\nint x=2;\nprintf(\"%d\\n\", x++);\nprintf(\"%d\",++x);\nreturn 0;\n}\n<\/pre>\n<p><strong>Output:-<\/strong><br \/>\n2<br \/>\n4<\/p>\n<p><strong>Q.20<\/strong> Why does the C programming language not support function overloading?<\/p>\n<p><strong>Ans.<\/strong> The C programming language does not support strict typing. In C, many things are implicitly convertible to each other. In C, if you introduce function overloading then you should provide a name mangling technique to prevent the name clashes. When you compile a C program code, the symbol names will remain intact.<\/p>\n<p><strong>Q.21<\/strong> Can you point out the error in the following code?<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">#include&lt;stdio.h&gt;\n\nint main()\n{\n  char c;\n  int x;\n  scanf(\"%c\", &amp;c);\n  scanf(\"%d\", &amp;x);\n  printf(\"%c %d\", c, x);\n  return 0;\n}\n<\/pre>\n<p><strong>Ans.<\/strong> The above program will give you an error because you will not get input for the second scanf() statement.<\/p>\n<p><strong>Q.22<\/strong> Why to use the new and delete operators in C?<\/p>\n<p><strong>Ans.<\/strong> The <strong>new<\/strong> operator is mainly used for allocating memory. With the help of this operator, you can return a pointer to the beginning of the new block of the allocated memory.<\/p>\n<p><strong>Example:-<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">int *ptr;\nptr = new int[20];\n<\/pre>\n<p>The <strong>delete<\/strong> operator is mainly used for deallocating memory. With the help of this operator, you can free the memory so that it will be available for other purposes.<\/p>\n<p><strong>Example:-<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">delete ptr;\n<\/pre>\n<p><strong>Q.23<\/strong> State the difference between call by value and call by reference.<\/p>\n<p><strong>Ans.<\/strong><\/p>\n<table>\n<tbody>\n<tr>\n<td><b>Call by Value<\/b><\/td>\n<td><b>Call by Reference<\/b><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">In this method, the actual values are passed to the function calls.<\/span><\/td>\n<td><span style=\"font-weight: 400\">In this method, instead of the actual values, the address of the corresponding values are passed to the function calls.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">Actual and Formal parameters are created at different memory locations.<\/span><\/td>\n<td><span style=\"font-weight: 400\">Actual and Formal parameters are created at the same memory locations.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">You cannot change the value of the actual parameter.<\/span><\/td>\n<td><span style=\"font-weight: 400\">You can change the value of the actual parameters by changing the formal parameter.<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><strong>Example:- call by value<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">#include&lt;stdio.h&gt;  \nvoid func(int n) {    \nn=n+50;    \nprintf(\"%d\\n\", n);    \n}    \nint main() {    \nint a=10;    \nfunc(a);  \nreturn 0;  \n}\t\n<\/pre>\n<p><strong>Output:-<\/strong><br \/>\n60<\/p>\n<p><strong>Example:- call by reference<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">#include&lt;stdio.h&gt;  \nvoid func(int *n) {    \n(*n) += 10;    \nprintf(\"%d\\n\", *n);    \n} \t \nint main() {    \nint a=10;    \nfunc(&amp;a);\nreturn 0;  \n}<\/pre>\n<p><strong>Output:-<\/strong><br \/>\n20<\/p>\n<p><strong>Q.24<\/strong> What is the output of the following program code?<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">#include&lt;stdio.h&gt;\nint fac(int);\nint npr(int, int);\nint main()\n{\n\n  int num=5, r=4;\n  int res;\n  res = npr(num, r);\n  printf(\"%d\\n\",res);\n  return 0;\n}\n\nint npr(int n1, int n2)\n{\n  return (fac(n1)\/fac(n1-n2));\n}\nint fac(int number)\n{\n  if(number == 1 || number == 0)\n    \treturn 1;\n  else\n    \treturn number*fac(number-1);\n}\n<\/pre>\n<p><strong>Ans.<\/strong> 120<\/p>\n<p><strong>Q.25<\/strong> Suppose, you created a file named Tech.txt. Then what will be the name of that file after executing the below program?<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">#include &lt;stdio.h&gt;\nint main()\n{\nint res;\nchar o[] = \"Tech.txt\";\nchar n[] = \"Advance.txt\";\nres = rename(o, n);\nif (res == 0)\nputs(\"success\");\nelse\nperror(\"Error\");\nreturn 0;\n}\n<\/pre>\n<p><strong>Ans.<\/strong> Advance<\/p>\n<h3>Advanced C Interview Questions and Answers<\/h3>\n<p><strong>Q.26<\/strong> What is the difference between getch() and getche()?<\/p>\n<p><strong>Ans.<\/strong> The <strong>getch()<\/strong> function is used to read a single character from the keyboard. The entered data will not display on the screen.<\/p>\n<p><strong>Example:- getch()<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">#include &lt;stdio.h&gt;\n#include &lt;conio.h&gt;\nint main()\n{\nprintf(\"Have a nice day!\");  \ngetch();   \nreturn 0;\n}\n<\/pre>\n<p>The above program will terminate immediately.<\/p>\n<p>The <strong>getche()<\/strong> function is used to read a single character from the keyboard. But the data will be displayed on the screen.<\/p>\n<p><strong>Example:- getche()<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">#include &lt;stdio.h&gt;\n#include &lt;conio.h&gt;\nint main()\n{\n  printf(\"Have a nice day!\");\n  getche();\n  return 0;\n}<\/pre>\n<p>The above program will terminate immediately too.<\/p>\n<p><strong>Q.27<\/strong> What is the output of the following program?<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">#include&lt;stdio.h&gt;\n#include&lt;conio.h&gt;\nvoid  main()\n{\nint i,j,k;\nfor(i=1;i&lt;=4;i++)\n{\nfor(j=4;j&gt;=i;j--)\nprintf(\" \");\nfor(k=1;k&lt;=i;k++)\nprintf(\"#\");\nprintf(\"\\n\");\n}\ngetch();\n}\n<\/pre>\n<p><strong>Ans.<\/strong><br \/>\n#<br \/>\n##<br \/>\n###<br \/>\n####<\/p>\n<p><strong>Q.28<\/strong> Can you tell me the errors occurred on the following program?<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">#include &lt;stdio.h&gt;\nint main()\n{\nint b=20,a=20;\nint res = add(b,a);\nprintf(\"%d\",res)\nreturn 0;\n}\n<\/pre>\n<p><strong>Ans.<\/strong> The function add() is not defined and there is no semicolon at the end of the printf() function.<\/p>\n<p><strong>Q.29<\/strong> Is it possible to override a defined macro? If yes, then how?<\/p>\n<p><strong>Ans.<\/strong> Yes, you can. For this, you have to use #ifdef and #undef preprocessors. Follow the code below:-<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">#ifdef A\n#undef A\n#endif\n#define SIZE 5\n<\/pre>\n<p>In the above, we defined a macro named SIZE. It can be undefined using the #undef and you can define it again using the #define.<\/p>\n<p><strong>Q.30<\/strong> Why to use the \u2018\\0\u2019 character in a string?<\/p>\n<p><strong>Ans.<\/strong> The main purpose of the \u2018\\0\u2019 character is to terminate a string. This is known as a null character. It automatically gets placed at the end of a string. It determines the end of the string.<\/p>\n<p><strong>Example:-<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">char *s =\"Hi\"; \/\/ it is actually Hi\\0\n<\/pre>\n<p><strong>Q.31<\/strong> Can you convert a queue to a stack? If \u201cYes\u201d then how?<\/p>\n<p><strong>Ans.<\/strong> Yes, you can convert a queue into a stack. You will need 2 stacks to create a queue from it. In C, you can do it in 2 ways:-<\/p>\n<ul>\n<li>Make the enqueue operation costly.<\/li>\n<li>Make the dequeue operation costly.<\/li>\n<\/ul>\n<p><strong>Implementing a stack using two queues<\/strong><br \/>\nIf you want to implement a stack using two queues then you need to make use of the stack operations with the help of queue operations:<\/p>\n<ul>\n<li>push(element A):-\n<ul>\n<li>If queue1 is empty, enqueue A to queue1<\/li>\n<li>If queue1 is not empty then enqueue all the elements from queue1 to queue2.<\/li>\n<\/ul>\n<\/li>\n<li>pop:-\n<ul>\n<li>Dequeue an element from queue1<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>Queue1 is the main source for the stack. And Queue2 acts as a helper queue.<\/p>\n<p><strong>Q.32<\/strong> Without using the semicolon to terminate the <strong>printf()<\/strong> function, how can you print the \u201cTechVidvan\u201d string?<\/p>\n<p><strong>Ans.<\/strong> You can use the <strong>if<\/strong> statement to print a string without using the semicolon at the end of the printf() function.<\/p>\n<p><strong>Example:- printf() function<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">#include&lt;stdio.h&gt; \nint main() \n{ \nif(printf(\"TechVidvan\")) \n{}\nreturn 0; \n}\n<\/pre>\n<p><strong>Output:-<\/strong><br \/>\nTechVidvan<\/p>\n<p><strong>Q.33<\/strong> Can you guess the output of the following program?<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">#include&lt;stdio.h&gt;\n#include&lt;conio.h&gt;\nvoid main()\n{\nint a=10,b=4;\na&gt;&gt;=2;\nb=a;\nprintf(\"%d \",b);\ngetch();\n}\n<\/pre>\n<p><strong>Ans.<\/strong> 2<\/p>\n<p><strong>Q.34<\/strong> What is the output of the following program code?<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">#include&lt;stdio.h&gt;\n#include&lt;conio.h&gt;\nvoid main()\n{\nint x=-4,y=-20,z=-10;\nif((x&gt;y)&amp;&amp;(x&gt;z))\nprintf(\"x is bigger!\");\nif((y&gt;z)&amp;&amp;(y&gt;x))\nprintf(\"y is bigger\");\nif((z&gt;x)&amp;&amp;(z&gt;y))\nprintf(\"z is bigger\");\ngetch();\n}\n<\/pre>\n<p><strong>Ans.<\/strong> x is bigger.<\/p>\n<p><strong>Q.35<\/strong> What is the output of the following program?<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">#include &lt;stdio.h&gt;\nint main()\n{\nvoid *ptr;\nint i=2;\nint *p=&amp;i;\nptr=p;\nprintf(\"%d\",(int*)*ptr);\nreturn 0;\n}\n<\/pre>\n<p><strong>Ans.<\/strong> It will give you a compile error. Because you cannot apply indirection on type void*.<\/p>\n<h3>Summary<\/h3>\n<p>You have to practice more to improve your coding skills in C. You should master the basic concepts of the C programming language. In this tutorial, we discussed some interview or job level questions of the C programming language and we also gave their answers. These questions will help you to prepare for the interview. And you will get better knowledge of the C programming language.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The C programming language is the base for all programming languages. C is one of the oldest and still most used programming languages. It is simple to understand and it supports fast compilation. C&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":85244,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3510],"tags":[4341,4335,4342],"class_list":["post-84822","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-c-programming","tag-c-basic-interview-questions","tag-c-interview-questions","tag-c-programming-interview-questions-answers"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.7 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>C Interview Questions - TechVidvan<\/title>\n<meta name=\"description\" content=\"Check these top interview questions and answers on C Programming language. It covers basic, intermediate &amp; advance level interview questions.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/techvidvan.com\/tutorials\/c-interview-questions\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"C Interview Questions - TechVidvan\" \/>\n<meta property=\"og:description\" content=\"Check these top interview questions and answers on C Programming language. It covers basic, intermediate &amp; advance level interview questions.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/techvidvan.com\/tutorials\/c-interview-questions\/\" \/>\n<meta property=\"og:site_name\" content=\"TechVidvan\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/TechVidvan\/\" \/>\n<meta property=\"article:published_time\" content=\"2021-10-04T03:30:34+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2021\/09\/c-interview-questions.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"628\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"TechVidvan Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@vidvantech\" \/>\n<meta name=\"twitter:site\" content=\"@vidvantech\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"TechVidvan Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"12 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"C Interview Questions - TechVidvan","description":"Check these top interview questions and answers on C Programming language. It covers basic, intermediate & advance level interview questions.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/techvidvan.com\/tutorials\/c-interview-questions\/","og_locale":"en_US","og_type":"article","og_title":"C Interview Questions - TechVidvan","og_description":"Check these top interview questions and answers on C Programming language. It covers basic, intermediate & advance level interview questions.","og_url":"https:\/\/techvidvan.com\/tutorials\/c-interview-questions\/","og_site_name":"TechVidvan","article_publisher":"https:\/\/www.facebook.com\/TechVidvan\/","article_published_time":"2021-10-04T03:30:34+00:00","og_image":[{"width":1200,"height":628,"url":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2021\/09\/c-interview-questions.jpg","type":"image\/jpeg"}],"author":"TechVidvan Team","twitter_card":"summary_large_image","twitter_creator":"@vidvantech","twitter_site":"@vidvantech","twitter_misc":{"Written by":"TechVidvan Team","Est. reading time":"12 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/techvidvan.com\/tutorials\/c-interview-questions\/#article","isPartOf":{"@id":"https:\/\/techvidvan.com\/tutorials\/c-interview-questions\/"},"author":{"name":"TechVidvan Team","@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/person\/e9c26e74dd3d87421f7ada9433b8cd22"},"headline":"C Interview Questions","datePublished":"2021-10-04T03:30:34+00:00","mainEntityOfPage":{"@id":"https:\/\/techvidvan.com\/tutorials\/c-interview-questions\/"},"wordCount":2070,"commentCount":0,"publisher":{"@id":"https:\/\/techvidvan.com\/tutorials\/#organization"},"image":{"@id":"https:\/\/techvidvan.com\/tutorials\/c-interview-questions\/#primaryimage"},"thumbnailUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2021\/09\/c-interview-questions.jpg","keywords":["C basic interview questions","C Interview Questions","C Programming Interview Questions Answers"],"articleSection":["C Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/techvidvan.com\/tutorials\/c-interview-questions\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/techvidvan.com\/tutorials\/c-interview-questions\/","url":"https:\/\/techvidvan.com\/tutorials\/c-interview-questions\/","name":"C Interview Questions - TechVidvan","isPartOf":{"@id":"https:\/\/techvidvan.com\/tutorials\/#website"},"primaryImageOfPage":{"@id":"https:\/\/techvidvan.com\/tutorials\/c-interview-questions\/#primaryimage"},"image":{"@id":"https:\/\/techvidvan.com\/tutorials\/c-interview-questions\/#primaryimage"},"thumbnailUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2021\/09\/c-interview-questions.jpg","datePublished":"2021-10-04T03:30:34+00:00","description":"Check these top interview questions and answers on C Programming language. It covers basic, intermediate & advance level interview questions.","breadcrumb":{"@id":"https:\/\/techvidvan.com\/tutorials\/c-interview-questions\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/techvidvan.com\/tutorials\/c-interview-questions\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/techvidvan.com\/tutorials\/c-interview-questions\/#primaryimage","url":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2021\/09\/c-interview-questions.jpg","contentUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2021\/09\/c-interview-questions.jpg","width":1200,"height":628,"caption":"c interview questions"},{"@type":"BreadcrumbList","@id":"https:\/\/techvidvan.com\/tutorials\/c-interview-questions\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/techvidvan.com\/tutorials\/"},{"@type":"ListItem","position":2,"name":"C Interview Questions"}]},{"@type":"WebSite","@id":"https:\/\/techvidvan.com\/tutorials\/#website","url":"https:\/\/techvidvan.com\/tutorials\/","name":"TechVidvan Blogs","description":"","publisher":{"@id":"https:\/\/techvidvan.com\/tutorials\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/techvidvan.com\/tutorials\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/techvidvan.com\/tutorials\/#organization","name":"TechVidvan","url":"https:\/\/techvidvan.com\/tutorials\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/logo\/image\/","url":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2024\/03\/techvidvan-logo-200x50-1.webp","contentUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2024\/03\/techvidvan-logo-200x50-1.webp","width":200,"height":50,"caption":"TechVidvan"},"image":{"@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/TechVidvan\/","https:\/\/x.com\/vidvantech"]},{"@type":"Person","@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/person\/e9c26e74dd3d87421f7ada9433b8cd22","name":"TechVidvan Team","description":"The TechVidvan Team delivers practical, beginner-friendly tutorials on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. Our experts are here to help you upskill and excel in today\u2019s tech industry."}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/posts\/84822","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/comments?post=84822"}],"version-history":[{"count":0,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/posts\/84822\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/media\/85244"}],"wp:attachment":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/media?parent=84822"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/categories?post=84822"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/tags?post=84822"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}