{"id":84612,"date":"2021-10-08T09:00:38","date_gmt":"2021-10-08T03:30:38","guid":{"rendered":"https:\/\/techvidvan.com\/tutorials\/?p=84612"},"modified":"2021-10-08T09:00:38","modified_gmt":"2021-10-08T03:30:38","slug":"c-programming-interview-questions-and-answers","status":"publish","type":"post","link":"https:\/\/techvidvan.com\/tutorials\/c-programming-interview-questions-and-answers\/","title":{"rendered":"C Programming Interview Questions and Answers"},"content":{"rendered":"<p>In this tutorial, we will discuss C interview questions with their answers. These questions are from the core and important concepts of the C programming language. To attempt these questions rightly, you will have to master the basic concepts of the C programming language.<\/p>\n<p>We have divided the C Interview question answers into 3 parts as C Interview questions for beginners, C Programming Interview Questions for intermediate and Advance C Language Interview Questions.<\/p>\n<p>If you read through these questions and also give the right answers to these following questions then it will help you to prepare better for placement and interviews. 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 programming Interview Questions for Beginners<\/h3>\n<p>Below are the C interview questions with answers for beginners.<\/p>\n<p><strong>Q.1<\/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(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.2<\/strong> What is the use of \u2018\\b\u2019 in the following program?<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">#include &lt;stdio.h&gt;\nint main(void)\n{\nprintf(\"Advance\\be\");\nreturn 0;\n}\n<\/pre>\n<p><strong>Ans.<\/strong> The <strong>\u2018\\b\u2019<\/strong> is an escape sequence that is used to move the cursor backwards. It normally does what backspace does on your keyboard. The above will print <strong>Advance<\/strong> to the screen.<\/p>\n<p><strong>Q.3<\/strong> If you open a file through the fopen() function then which parameters will fseek() require to work with that file?<\/p>\n<p><strong>Ans.<\/strong> First, the number of bytes to search for. Second, the point of origin of that file and third, a file pointer to that file.<\/p>\n<p><strong>fopen() function<\/strong><br \/>\nThe main purpose of the fopen() function is to open a file to perform several operations which includes reading, writing, editing etc.<\/p>\n<p><strong>Syntax<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">FILE *fopen(const char *filename, const char *operation_mode);\n<\/pre>\n<p>The function returns null if the execution does not succeed and if it succeeds then it returns a pointer to FILE.<\/p>\n<p><strong>fseek() function<\/strong><br \/>\nThe main purpose of the fseek() function is to set the file pointer of the stream to a given offset. To put it short, you can use this function for writing data into a file at a specified location.<\/p>\n<p><strong>Syntax<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">int fseek(FILE *stream, long int offset, int pos) \n<\/pre>\n<p><strong>Q.4<\/strong> What is the output of the following program?<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">#define add(data) data+data\nint main()\n{\nint data;\ndata = 36\/add(10);\nprintf(\"%d\",data);\nreturn 0;\n}\n<\/pre>\n<p><strong>Ans.<\/strong> 13<\/p>\n<p><strong>Q.5<\/strong> Suppose, a block of memory is allocated. Can you free that block of memory which is allocated? If yes, how?<\/p>\n<p><strong>Ans.<\/strong> Yes, you can free the previously allocated block of memory with the help of free() function.<\/p>\n<p><strong>free() function in C<\/strong><br \/>\nThe free() function is mainly used to deallocate a block of memory which was allocated previously. It calls malloc, calloc or realloc to perform the task. And it does not return any value.<\/p>\n<p><strong>Declaration<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">void free(void *pointer)\n<\/pre>\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;\n#include &lt;string.h&gt;\n\nint main () {\n   char *st;\n\n   st = (char *) malloc(20);\n   strcpy(st, \"C\");\n   printf(\"%s =&gt; %u\\n\", st, st);\n\n   st = (char *) realloc(st, 20);\n   strcat(st, \" Quiz\");\n   printf(\"%s =&gt; %u\", st, st);\n   free(st);\n   \n   return(0);\n}\n<\/pre>\n<p><strong>Output:-<\/strong><br \/>\nC =&gt; 27021328<br \/>\nC Quiz =&gt; 27021328<\/p>\n<p><strong>Q.6<\/strong> In C programs, why is it a bad practice to make use of the gets() function?<\/p>\n<p><strong>Ans.<\/strong> The problem in using the gets() function is that it does not know how big the buffer is. That\u2019s why it continues to read until it finds a newline or encounters EOF and it may result in buffer overflow.<\/p>\n<p><strong>gets() function<\/strong><br \/>\nIt reads a line from stdin and it stores the line into the string that is pointed by the str. It is a bad practice to use the gets() function in your program code. Because it keeps reading the line until it reaches a newline character.<\/p>\n<p><strong>Declaration<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">char *gets(char *str)\n<\/pre>\n<p><strong>Example:-<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">#include &lt;stdio.h&gt;\n\nint main () {\n   char st[50];\n\n   printf(\"Enter something: \");\n   gets(st);\n   printf(\"%s\", st);\n   return(0);\n}\n<\/pre>\n<p><strong>Output:-<\/strong><br \/>\nEnter something: Nice Day<br \/>\nNice Day<\/p>\n<p><strong>Q.7<\/strong> Why is the following program dangerous?<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">#include&lt;stdio.h&gt;\nint main(int argc, char** argv)\n{\nchar buffer[100];\nstrncpy(buffer, argv[1], 100);\nprintf(buffer);\nreturn 0;\n}\n<\/pre>\n<p><strong>Ans.<\/strong> In that above program, we pass an attacker-controlled buffer as an argument to a printf() function. With this, the attacker can perform writing to arbitrary memory addresses. You must use the format string to determine the number of arguments in the printf() function.<\/p>\n<p><strong>Q.8<\/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{\n  int arr[3] = {2,5,9};\n  int *pt = (int*)(&amp;arr+1);\n  printf(\"%d\",*(pt-1));\n  return 0;\n}\n<\/pre>\n<p><strong>Ans.<\/strong> 9<\/p>\n<p><strong>Q.9<\/strong> What is the output of the following program?<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">int main(){\nfloat  d ;\nint a=20,b=3;\nd = ( int ) a \/ b ;\nprintf(\"%f\",d);\nreturn 0;\n}\n<\/pre>\n<p><strong>Ans.<\/strong> 6.000000<\/p>\n<p><strong>Q.10<\/strong> Can you tell me the errors that 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.11<\/strong> In any C program, can you execute that program without including any header files into it?<\/p>\n<p><strong>Ans.<\/strong> In some compilers, yes you can. But it will give you a warning to include the following header file to the program code. But in some compilers, you can\u2019t. Because you will have to include a header file named <strong>stdio.h.<\/strong><br \/>\nIf you are using some predefined functions such as free(), strcat(), time() etc then you have to use their own header files in which they are defined.<\/p>\n<p><strong>Example:-<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">int printf(const char *format, ...);\nint main()\n{\n  printf( \"Have a nice day!\" );\n  return 0;\n}\n<\/pre>\n<p><strong>Output:-<\/strong><br \/>\nHave a nice day!<\/p>\n<p><strong>Q.12<\/strong> What is the output of the following program?<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">int main()\n{\n char *point = \"Amen\";\n printf(\"%c\", *&amp;*&amp;*point);\n return 0;\n}\n<\/pre>\n<p><strong>Ans.<\/strong> A<\/p>\n<p><strong>Q.13<\/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{\nwhile (printf(\"Have a good day!\"))\nreturn 0;\n}\n<\/pre>\n<p><strong>Ans.<\/strong> Have a good day!!<\/p>\n<h3>Intermediate Level C Interview Questions<\/h3>\n<p><strong>Q.14<\/strong> Can you tell me the ways to convert a string to integer value?<\/p>\n<p><strong>Ans. First Method:-<\/strong><br \/>\nYou can use the existing atoi() function in C. The main purpose of this is to convert the string argument to an integer.<\/p>\n<p><strong>Declaration<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">int data = atoi(string1);\n<\/pre>\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;\n#include &lt;string.h&gt;\n\nint main () {\n   int data;\n   char st[20];\n   strcpy(st, \"123\");\n   data = atoi(st);\n   printf(\"%d\",data);\n\n   return(0);\n}\n<\/pre>\n<p><strong>Output:-<\/strong><br \/>\n123<\/p>\n<p><strong>Second Method:-<\/strong><br \/>\nYou can also use the sscanf() function. The main purpose of this function is to read formatted input from a string.<\/p>\n<p><strong>Declaration<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">int sscanf(const char *str, const char *format, ...)\n<\/pre>\n<p><strong>Example:-<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">sscanf(string1,\u201d%d\u201d,&amp;data)\n<\/pre>\n<p><strong>Q.15<\/strong> Suppose, you included the same header files twice in your program. Then, how can you avoid including the same header files twice in your program code?<\/p>\n<p><strong>Ans.<\/strong> You can make use of the ifndef and define preprocessor directives. Suppose, the header file is header.h then you can include the header file like below:-<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">#ifndef header.h\n#define header.h\n#endif\n<\/pre>\n<p>In the above, the ifndef will check if the header.h is defined or not. If it is not then it will define the header.h file.<\/p>\n<p><strong>Q.16<\/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{\n    for(;;)\n    printf(\"Hi, John Here!\");\n    return 0;\n}\n<\/pre>\n<p><strong>Ans.<\/strong> The above program will print the<strong> Hi, John Here!<\/strong> text infinitely.<\/p>\n<p><strong>Q.17<\/strong> Can you tell the difference between const char* ptr and char const* ptr?<\/p>\n<p><strong>Ans.<\/strong><\/p>\n<p><strong>NOTE:-<\/strong> A pointer should always point to the same address but the value at the location is changed.<\/p>\n<p><strong>const char* ptr<\/strong><br \/>\nThe character is pointed by the pointer variable ptr. You cannot change the value but you can initialize the ptr with another memory location.<\/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{\n  char x ='X', y ='Y';\n  const char *pt = &amp;x;\n  printf( \"The value pointed by pt-&gt; %c\\n\", *pt);\n  pt = &amp;y;\n  printf( \"The value pointed by pt-&gt; %c\\n\", *pt);\n}\n<\/pre>\n<p><strong>Output:-<\/strong><br \/>\nThe value pointed by pt-&gt; X<br \/>\nThe value pointed by pt-&gt; Y<\/p>\n<p><strong>char const* ptr<\/strong><br \/>\nThe pointer ptr is constant. You cannot assign ptr with another memory location but you can change the value of the character pointed by ptr.<\/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{\n  char x ='X', y ='Y';\n  char *const pt = &amp;x;\n  printf( \"The value pointed by pt: %c\\n\", *pt);\n  printf( \"pointing to: %d\\n\", pt);\n  *pt = y;\n  printf( \"The value pointed by pt: %c\\n\", *pt);\n  printf( \"pointing to: %d\\n\", pt);\n}\n<\/pre>\n<p><strong>Output:-<\/strong><br \/>\nThe value pointed by pt: X<br \/>\npointing to: 936799398<br \/>\nThe value pointed by pt: Y<br \/>\npointing to: 936799398<\/p>\n<p><strong>Q.18<\/strong> How can you allocate a single block of memory dynamically in the C programming language?<\/p>\n<p><strong>Ans.<\/strong> In C, you can make use of malloc() function to allocate a single block of memory dynamically in C. This function is defined in the <strong>stdlib.h<\/strong> header file. It returns a pointer to the allocated memory.<\/p>\n<p><strong>Syntax of malloc()<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">ptr = (cast-type*) malloc(byte-size)\n<\/pre>\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;\n#include &lt;string.h&gt;\n\nint main () {\n   char *st;\n\n   st = (char *) malloc(20);\n   strcpy(st, \"Good\");\n   printf(\"%s =&gt; %u\\n\", st, st);\n\n   st = (char *) realloc(st, 20);\n   strcat(st, \" Day\");\n   printf(\"%s =&gt; %u\", st, st);\n   free(st);\n   \n   return(0);\n}\n<\/pre>\n<p><strong>Output:-<\/strong><br \/>\nGood =&gt; 36782096<br \/>\nGood Day =&gt; 36782096<\/p>\n<p><strong>Q.19<\/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[] = \"random.txt\";\nres = rename(o, n);\nif (res == 0)\nputs(\"success\");\nelse\nperror(\"Error\");\nreturn 0;\n}\n<\/pre>\n<p><strong>Ans.<\/strong> random<\/p>\n<p><strong>Q.20<\/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.21<\/strong> Write a code to print the following pattern?<\/p>\n<p>####<br \/>\n###<br \/>\n##<br \/>\n#<\/p>\n<p><strong>Ans.<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">#include &lt;stdio.h&gt;\nint main() {\nint i, j, rows=4;\nfor (i = rows; i &gt;= 1; --i) {\nfor (j = 1; j &lt;= i; ++j) {\nprintf(\"#\");\n}\nprintf(\"\\n\");\n}\nreturn 0;\n}\n<\/pre>\n<p><strong>Q.22<\/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{\ntypedef struct Tech{\nchar string[14];\nint data;\n}tech;\ntech s1, s2 = { \"B\\bBook!\", 14};\ns1 = s2;\ns1.string[0] = 't';\nprintf(\"%s %d\", s1.string, s1.data);\nreturn 0;\n}\n<\/pre>\n<p><strong>Ans.<\/strong> Book! 14<\/p>\n<p><strong>Q.23<\/strong> You can include header files into the C program in 2 ways using &lt;&gt; and \u201c\u201d. What is the difference between &lt;&gt; and \u201c\u201d?<\/p>\n<p><strong>Ans.<\/strong> If you declare the header file using &lt;&gt; then the compiler will search for that header file in the built-in library. But if you declare the header file using \u201c\u201d then the compiler will search for that header file in the current working directory.<\/p>\n<p>We have created our own header file named header.h.<\/p>\n<p><strong>header.h<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">#ifndef header_file  \n#define header_file  \nint x = 22;  \n#endif\n<\/pre>\n<p>Below is the source code which uses the header file:-<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">#include &lt;stdio.h&gt;  \n#include \"header.h\"   \nint main()  \n{\nprintf(\"Value of x: %d\", x);  \nreturn 0;  \n}\n<\/pre>\n<p><strong>Output:-<\/strong><br \/>\nValue of x: 22<\/p>\n<p><strong>Q.24<\/strong> In C, can you add pointers to each other?<\/p>\n<p><strong>Ans.<\/strong> No, you cannot add pointers together. It is not possible. Pointers contain addresses and you cannot retrieve the value out of this operation. If you add addresses then it won\u2019t make sense. But you can subtract two addresses to find the offset between those addresses. It is a very useful one. You can also crash the code by adding pointers or it can result in overflow.<\/p>\n<h3>Advance C Language Interview Question Answer<\/h3>\n<p><strong>Q.25<\/strong> Is it possible to print a string with the % symbol in it? If yes, how?<\/p>\n<p><strong>Ans.<\/strong> Yes, you can.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">To print \u2018%\u2019, you have to use \u2018%%\u2019. Follow the code below:-\nprintf(\u201cThis shirt has 30%% discount!\u201d);\n<\/pre>\n<p><strong>Q.26<\/strong> Can you tell what the below statement is doing?<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">typedef int REAL, *REALP, ONE[10];\n<\/pre>\n<p><strong>Ans.<\/strong> \u201cREAL a\u201d is used to define a type int. \u201cREALP *b\u201d would define pointer b of type int **. \u201cONE a1\u201d would define a1 as an array of 10 int.<\/p>\n<p><strong>Q.27<\/strong> Can you describe what the below expression is doing?<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">struct {int a[3];} arr[] = {2,1,3};\n<\/pre>\n<p><strong>Ans.<\/strong> The above expression will create an array <strong>arr<\/strong> of 1 element. Then each of the elements of arr contain a struct field of int array of 3 elements. arr[0].a[0] is 2, arr[1].a[1] is 1 and arr[2].a[2] is 3. There is nothing wrong with the expression.<\/p>\n<p><strong>Q.28<\/strong> Is the below expression correct?<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">int arr[40] = {1,2,3,[37]=38,39,40};\n<\/pre>\n<p><strong>Ans.<\/strong> Yes, the above expression is correct. The above statement will initialize arr[1], arr[2], arr[3] \u2026, arr[38], arr[39], arr[40] to 1,2,3,4,&#8230;,38,39,40. And the remaining elements of that array will be initialized to 0.<\/p>\n<p><strong>Q.29<\/strong> What is the output of the below program code?<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">#include &lt;stdio.h&gt;\nint fun(int num)\n{\n   static int i = 1;\n   if (num &gt;= 5)\n  \treturn num;\n   num=num+i;\n   i++;\n   return fun(num);\n}\nint main(){\n  int n = fun(2);\n  printf(\"%d\",n);\n}\n<\/pre>\n<p><strong>Ans.<\/strong> 5<\/p>\n<p><strong>Q.30<\/strong> For comparing strings in C, can you use the if function?<\/p>\n<p><strong>Ans.<\/strong> No, you cannot use the if function to compare strings. It is only used to compare numeric and single character values. For comparing strings, you can use the strcmp() function.<\/p>\n<p><strong>Declaration<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">int strcmp(const char *s1, const char *s2)\n<\/pre>\n<p>If the return value of the function is less than 0 then s1 is less than s2 and if it is greater than 0 then s2 is less than s1. And it is equal to 0 then s1 and s2 both are the same.<\/p>\n<p><strong>Example:-<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">#include &lt;stdio.h&gt;\n#include &lt;string.h&gt;\nint main() {\n  char s1[] = \"abcd\", s2[] = \"abCd\";\n  int result;\n  result = strcmp(s1, s2);\n  printf(\"%d\\n\", result);\n  return 0;\n}\n<\/pre>\n<p><strong>Output:-<\/strong><br \/>\n1<\/p>\n<p><strong>Q.31<\/strong> Are the uninitialized pointer and the null pointer the same in C?<\/p>\n<p><strong>Ans.<\/strong> Null pointer is a pointer which points to nothing. Value of the null pointer is 0. Below we made a pointer to point to null:-<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">int *ptr = NULL;\nchar *ptr = NULL;\n<\/pre>\n<p>The uninitialized pointer is also known as a wild pointer. This pointer points to an arbitrary memory location. It is a bad practice to use the uninitialized pointer. It can have a valid pointer value in it.<\/p>\n<p><strong>Example:- null pointer<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">#include &lt;stdio.h&gt;  \nint main()  \n{  \nint *ptr=NULL;  \nprintf(\"value =&gt; ptr: %d\",*ptr);  \nreturn 0;  \n} \n<\/pre>\n<p>The above program will not print anything back to the screen because of the null pointer.<\/p>\n<p><strong>Example:- uninitialized pointer<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">int main()\n{\nint *p;\nint x = 10;\nreturn 0;\n}\n<\/pre>\n<p><strong>Q.32<\/strong> What will be the output of the following program?<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">#include &lt;stdio.h&gt;\nint main()\n{\n  int a = 0xf;\n  int b = 0x63;\n  printf(\"%x\",(a^b));\n  return 0;\n}\n<\/pre>\n<p><strong>Ans.<\/strong> 6c<\/p>\n<p><strong>Q.33<\/strong> What is the output of the following program?<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">#include &lt;stdio.h&gt;\n#define A 20\n#define B 5\nint main()\n{\nint (*ptr)[A][B];\nprintf(\"%d\",  sizeof(*ptr));\nreturn 0;\n}\n<\/pre>\n<p><strong>Ans.<\/strong> 400<\/p>\n<p><strong>Q.34<\/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>Above, we defined a macro named SIZE. It can be undefined using the #undef and it can be define again using the #define.<\/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 foo(unsigned int n, unsigned int r) {\n  if (n  &gt; 0) return (n%r +  foo (n\/r, r ));\n  else return 0;\n}\nint main()\n{\nint res;\nres = foo(340,10);\nprintf(\"%d\",  res);\nreturn 0;\n}\n<\/pre>\n<p><strong>Ans.<\/strong> 7<\/p>\n<h3>Summary<\/h3>\n<p>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 better for the interview. And you will also get better knowledge of the C programming language through this.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this tutorial, we will discuss C interview questions with their answers. These questions are from the core and important concepts of the C programming language. To attempt these questions rightly, you will have&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":85247,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3510],"tags":[4406,4336,4342],"class_list":["post-84612","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-c-programming","tag-c-interview-questions-answers","tag-c-programming-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 Programming Interview Questions and Answers - TechVidvan<\/title>\n<meta name=\"description\" content=\"Check these C Programming Interview Questions and Answers that will help you to check your knowledge and preparation for C Interviews.\" \/>\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-programming-interview-questions-and-answers\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"C Programming Interview Questions and Answers - TechVidvan\" \/>\n<meta property=\"og:description\" content=\"Check these C Programming Interview Questions and Answers that will help you to check your knowledge and preparation for C Interviews.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/techvidvan.com\/tutorials\/c-programming-interview-questions-and-answers\/\" \/>\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-08T03:30:38+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2021\/08\/c-programming-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 Programming Interview Questions and Answers - TechVidvan","description":"Check these C Programming Interview Questions and Answers that will help you to check your knowledge and preparation for C Interviews.","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-programming-interview-questions-and-answers\/","og_locale":"en_US","og_type":"article","og_title":"C Programming Interview Questions and Answers - TechVidvan","og_description":"Check these C Programming Interview Questions and Answers that will help you to check your knowledge and preparation for C Interviews.","og_url":"https:\/\/techvidvan.com\/tutorials\/c-programming-interview-questions-and-answers\/","og_site_name":"TechVidvan","article_publisher":"https:\/\/www.facebook.com\/TechVidvan\/","article_published_time":"2021-10-08T03:30:38+00:00","og_image":[{"width":1200,"height":628,"url":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2021\/08\/c-programming-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-programming-interview-questions-and-answers\/#article","isPartOf":{"@id":"https:\/\/techvidvan.com\/tutorials\/c-programming-interview-questions-and-answers\/"},"author":{"name":"TechVidvan Team","@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/person\/e9c26e74dd3d87421f7ada9433b8cd22"},"headline":"C Programming Interview Questions and Answers","datePublished":"2021-10-08T03:30:38+00:00","mainEntityOfPage":{"@id":"https:\/\/techvidvan.com\/tutorials\/c-programming-interview-questions-and-answers\/"},"wordCount":1889,"commentCount":0,"publisher":{"@id":"https:\/\/techvidvan.com\/tutorials\/#organization"},"image":{"@id":"https:\/\/techvidvan.com\/tutorials\/c-programming-interview-questions-and-answers\/#primaryimage"},"thumbnailUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2021\/08\/c-programming-interview-questions.jpg","keywords":["C Interview Questions ANswers","C Programming Interview Questions","C Programming Interview Questions Answers"],"articleSection":["C Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/techvidvan.com\/tutorials\/c-programming-interview-questions-and-answers\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/techvidvan.com\/tutorials\/c-programming-interview-questions-and-answers\/","url":"https:\/\/techvidvan.com\/tutorials\/c-programming-interview-questions-and-answers\/","name":"C Programming Interview Questions and Answers - TechVidvan","isPartOf":{"@id":"https:\/\/techvidvan.com\/tutorials\/#website"},"primaryImageOfPage":{"@id":"https:\/\/techvidvan.com\/tutorials\/c-programming-interview-questions-and-answers\/#primaryimage"},"image":{"@id":"https:\/\/techvidvan.com\/tutorials\/c-programming-interview-questions-and-answers\/#primaryimage"},"thumbnailUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2021\/08\/c-programming-interview-questions.jpg","datePublished":"2021-10-08T03:30:38+00:00","description":"Check these C Programming Interview Questions and Answers that will help you to check your knowledge and preparation for C Interviews.","breadcrumb":{"@id":"https:\/\/techvidvan.com\/tutorials\/c-programming-interview-questions-and-answers\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/techvidvan.com\/tutorials\/c-programming-interview-questions-and-answers\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/techvidvan.com\/tutorials\/c-programming-interview-questions-and-answers\/#primaryimage","url":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2021\/08\/c-programming-interview-questions.jpg","contentUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2021\/08\/c-programming-interview-questions.jpg","width":1200,"height":628,"caption":"c programming interview questions"},{"@type":"BreadcrumbList","@id":"https:\/\/techvidvan.com\/tutorials\/c-programming-interview-questions-and-answers\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/techvidvan.com\/tutorials\/"},{"@type":"ListItem","position":2,"name":"C Programming Interview Questions and Answers"}]},{"@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\/84612","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=84612"}],"version-history":[{"count":0,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/posts\/84612\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/media\/85247"}],"wp:attachment":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/media?parent=84612"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/categories?post=84612"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/tags?post=84612"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}