{"id":2654,"date":"2021-04-07T09:53:09","date_gmt":"2021-04-07T09:53:09","guid":{"rendered":"https:\/\/www.prepbytes.com\/blog\/?p=2654"},"modified":"2022-03-21T12:16:42","modified_gmt":"2022-03-21T12:16:42","slug":"commonly-asked-interview-questions-on-c","status":"publish","type":"post","link":"https:\/\/prepbytes.com\/blog\/commonly-asked-interview-questions-on-c\/","title":{"rendered":"Commonly asked interview questions on c"},"content":{"rendered":"<ol>\n<li><strong>Why do we still use C? Isn\u2019t it quite old?<\/strong><br \/>\nAns. C is considered to be the mother of all modern-day languages. It was initially created for the purpose of making operating systems. Specifically, it was used in UNIX operating system. It is as fast as assembly languages and hence are the first priority for system development. Other programs that usually use C for their development are \u2013 Assembler, text editors, databases, Utility tools etc.<\/li>\n<li><strong>What are storage class specifiers and how many of them do you know?<\/strong><br \/>\nAns. A storage class defines the scope and lifetime of variables or functions in C. There are four different storage classes in C \u2013<\/p>\n<ul>\n<li>Auto<\/li>\n<li>Register<\/li>\n<li>Static<\/li>\n<li>Extern<\/li>\n<\/ul>\n<\/li>\n<li><strong>What do you mean by scope of a variable?<\/strong><br \/>\nAns. It is the part of a program which can be directly accessed. In C all identifiers are statically scoped. C has basically 4 types of scope rules \u2013 File Scope, Block Scope, Function Prototype, Function Scope.<\/li>\n<li><strong>Can you print Hello! World without semicolon?<\/strong><br \/>\nAns. In C printf function returns the number of characters written in stdout and performs the function.<\/p>\n<pre><code>#include &lt;stdio.h&gt; \nint main(void) \n{ \nif (printf (&quot;Hello World&quot;)) { \n} \n}<\/code><\/pre>\n<\/li>\n<li><strong>Do you know about pointers? Can you explain about far pointer?<\/strong><br \/>\nAns. Yes, Pointers are basically variables which refers to the address of a particular value.<br \/>\nA pointer which can access all 16 segments of the RAM is known far pointer.<\/li>\n<li><strong>Can you explain what is dangling pointer and how we can avoid it?<\/strong><br \/>\nAns. If a pointer is pointing to some address of a variable and at that moment another pointer is used to delete that variable or memory occupied then the first pointer points to a memory location which might not be accessible. The first pointer is known as Dangling pointer.<br \/>\nIt can easily be removed by making the first pointer point to null.<\/li>\n<li><strong>What is Static Memory Allocation?<\/strong><br \/>\nAns. Static memory allocation is when the memory is allocated at compile time. This memory cannot be increased while running a program. E.g., int arr[10]; the size of this array cannot be increased during run time. This is called static memory allocation.<\/li>\n<li><strong>Then what is dynamic memory allocation?<\/strong><br \/>\nAns. This memory allocation occurs during run time and can be easily changed. C uses malloc (), calloc (), realloc () for dynamic memory allocation. This memory is implemented using data section. Less memory space is wasted in this memory allocations.<\/li>\n<li><strong>Can you give the difference between malloc () and calloc ()?<\/strong><br \/>\nAns.<\/li>\n<\/ol>\n<table>\n<thead>\n<tr>\n<th style=\"text-align: center;\">Malloc()<\/th>\n<th style=\"text-align: center;\">Calloc ()<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td style=\"text-align: center;\">Malloc () function will create a single block of memory specified by the user.<\/td>\n<td style=\"text-align: center;\">Calloc () can assign multiple blocks of memory.<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\">Malloc() is faster but less secure<\/td>\n<td style=\"text-align: center;\">It is slower but more secure<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\">It does not initialize memory<\/td>\n<td style=\"text-align: center;\">It initialises memory to 0<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\">Returns only the starting address but does not make it 0<\/td>\n<td style=\"text-align: center;\">Returns the starting address and makes it 0<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<ol start=\"10\">\n<li><strong>Do you know about enumerations?<\/strong><br \/>\nAns. Enumerations are list of integer constants with name. It is defined in C as enum.<br \/>\nenum week{Mon,Tue,Wed,Thur,Fri,Sat,Sun} <\/li>\n<li><strong><strong>What is Union? Why do we need Union when we already have structures?<\/strong><\/strong><br \/>\nAns. Union is a data type that helps in storing multiple types of data in a single unit. It is different than structures as in structures the size of memory that is allocated is the sum of all the elements present in them which might use a lot of extra space. Union only allocates memory of the largest variable present in it. Although in Union, we can only access one variable at a time.<\/p>\n<pre><code>union unionstruct  \n{  \nint a; \/\/union members declaration.  \nfloat b; \/\/assigns memory to only size of float \nchar c;  \n};<\/code><\/pre>\n<\/li>\n<li><strong>Can you briefly explain at where do the variables are stored in C?<\/strong><br \/>\nAns. The following describes where each type of data is stored in C.<br \/>\nglobal variables &#8211; data<br \/>\nstatic variables &#8211; data<br \/>\nconstant data types &#8211; code and\/or data<br \/>\nlocal variables (declared and defined in functions) &#8211; stack<br \/>\nvariables declared and defined in main function &#8211; stack<br \/>\npointers &#8211; data or stack, depending on the context.<br \/>\ndynamically allocated space (using malloc, calloc, realloc)- heap<\/li>\n<li><strong>What is auto keyword and what is it\u2019s use?<\/strong><br \/>\nAns. Each variable defined inside a function is called a local variable, these local variables contain are known as automatic variables(auto). We do not need to explicitly define them as local. If it contains no value then it has garbage value.<\/li>\n<li><strong>Can you write a program without the use of main function?<\/strong><br \/>\nAns. Well, I can write a program without main function, but it will only get compiled. It cannot be executed without a main function.<\/li>\n<li><strong>Write a C program to check whether a given number is palindrome or not.<\/strong><br \/>\nAns. A number is palindrome if it is equal to its reverse<\/p>\n<pre><code>#include&lt;stdio.h&gt;    \n#include&lt;conio.h&gt;    \nmain()    \n{    \nint n,r,sum=0,temp;\nscanf(&quot;%d&quot;,&amp;n);    \ntemp=n;    \n\/\/ a number is palindrome if it is equal to it&#039;s reverse\nwhile(n&gt;0)   \/\/getting reverse of the number \n{    \nr=n%10;    \nsum=(sum*10)+r;    \nn=n\/10;    \n}    \nif(temp==sum)    \nprintf(&quot;palindrome &quot;);    \nelse    \nprintf(&quot;not palindrome&quot;);  \n}<\/code><\/pre>\n<\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>Why do we still use C? Isn\u2019t it quite old? Ans. C is considered to be the mother of all modern-day languages. It was initially created for the purpose of making operating systems. Specifically, it was used in UNIX operating system. It is as fast as assembly languages and hence are the first priority for [&hellip;]<\/p>\n","protected":false},"author":52,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[2],"tags":[],"class_list":["post-2654","post","type-post","status-publish","format-standard","hentry","category-c-programming"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v25.8 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Commonly asked interview questions on c | C Programming | PrepBytes Blog<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/prepbytes.com\/blog\/commonly-asked-interview-questions-on-c\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Commonly asked interview questions on c | C Programming | PrepBytes Blog\" \/>\n<meta property=\"og:description\" content=\"Why do we still use C? Isn\u2019t it quite old? Ans. C is considered to be the mother of all modern-day languages. It was initially created for the purpose of making operating systems. Specifically, it was used in UNIX operating system. It is as fast as assembly languages and hence are the first priority for [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/prepbytes.com\/blog\/commonly-asked-interview-questions-on-c\/\" \/>\n<meta property=\"og:site_name\" content=\"PrepBytes Blog\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/prepbytes0211\/\" \/>\n<meta property=\"article:published_time\" content=\"2021-04-07T09:53:09+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-03-21T12:16:42+00:00\" \/>\n<meta name=\"author\" content=\"Prepbytes\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Prepbytes\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/prepbytes.com\/blog\/commonly-asked-interview-questions-on-c\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/commonly-asked-interview-questions-on-c\/\"},\"author\":{\"name\":\"Prepbytes\",\"@id\":\"http:\/\/43.205.93.38\/#\/schema\/person\/3f7dc4ae851791d5947a7f99df363d5e\"},\"headline\":\"Commonly asked interview questions on c\",\"datePublished\":\"2021-04-07T09:53:09+00:00\",\"dateModified\":\"2022-03-21T12:16:42+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/commonly-asked-interview-questions-on-c\/\"},\"wordCount\":774,\"commentCount\":0,\"publisher\":{\"@id\":\"http:\/\/43.205.93.38\/#organization\"},\"articleSection\":[\"C Programming\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/prepbytes.com\/blog\/commonly-asked-interview-questions-on-c\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/prepbytes.com\/blog\/commonly-asked-interview-questions-on-c\/\",\"url\":\"https:\/\/prepbytes.com\/blog\/commonly-asked-interview-questions-on-c\/\",\"name\":\"Commonly asked interview questions on c | C Programming | PrepBytes Blog\",\"isPartOf\":{\"@id\":\"http:\/\/43.205.93.38\/#website\"},\"datePublished\":\"2021-04-07T09:53:09+00:00\",\"dateModified\":\"2022-03-21T12:16:42+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/commonly-asked-interview-questions-on-c\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/prepbytes.com\/blog\/commonly-asked-interview-questions-on-c\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/prepbytes.com\/blog\/commonly-asked-interview-questions-on-c\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"http:\/\/43.205.93.38\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"C Programming\",\"item\":\"https:\/\/prepbytes.com\/blog\/category\/c-programming\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Commonly asked interview questions on c\"}]},{\"@type\":\"WebSite\",\"@id\":\"http:\/\/43.205.93.38\/#website\",\"url\":\"http:\/\/43.205.93.38\/\",\"name\":\"PrepBytes Blog\",\"description\":\"ONE-STOP RESOURCE FOR EVERYTHING RELATED TO CODING\",\"publisher\":{\"@id\":\"http:\/\/43.205.93.38\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"http:\/\/43.205.93.38\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"http:\/\/43.205.93.38\/#organization\",\"name\":\"Prepbytes\",\"url\":\"http:\/\/43.205.93.38\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"http:\/\/43.205.93.38\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/blog.prepbytes.com\/wp-content\/uploads\/2025\/07\/uzxxllgloialmn9mhwfe.webp\",\"contentUrl\":\"https:\/\/blog.prepbytes.com\/wp-content\/uploads\/2025\/07\/uzxxllgloialmn9mhwfe.webp\",\"width\":160,\"height\":160,\"caption\":\"Prepbytes\"},\"image\":{\"@id\":\"http:\/\/43.205.93.38\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/prepbytes0211\/\",\"https:\/\/www.instagram.com\/prepbytes\/\",\"https:\/\/www.linkedin.com\/company\/prepbytes\/\",\"https:\/\/www.youtube.com\/channel\/UC0xGnHDrjUM1pDEK2Ka5imA\"]},{\"@type\":\"Person\",\"@id\":\"http:\/\/43.205.93.38\/#\/schema\/person\/3f7dc4ae851791d5947a7f99df363d5e\",\"name\":\"Prepbytes\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"http:\/\/43.205.93.38\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/232042cd1a1ea0e982c96d2a2ec93fb70a8e864e00784491231e7bfe5a9e06b5?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/232042cd1a1ea0e982c96d2a2ec93fb70a8e864e00784491231e7bfe5a9e06b5?s=96&d=mm&r=g\",\"caption\":\"Prepbytes\"},\"url\":\"https:\/\/prepbytes.com\/blog\/author\/gourav-jaincollegedekho-com\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Commonly asked interview questions on c | C Programming | PrepBytes Blog","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:\/\/prepbytes.com\/blog\/commonly-asked-interview-questions-on-c\/","og_locale":"en_US","og_type":"article","og_title":"Commonly asked interview questions on c | C Programming | PrepBytes Blog","og_description":"Why do we still use C? Isn\u2019t it quite old? Ans. C is considered to be the mother of all modern-day languages. It was initially created for the purpose of making operating systems. Specifically, it was used in UNIX operating system. It is as fast as assembly languages and hence are the first priority for [&hellip;]","og_url":"https:\/\/prepbytes.com\/blog\/commonly-asked-interview-questions-on-c\/","og_site_name":"PrepBytes Blog","article_publisher":"https:\/\/www.facebook.com\/prepbytes0211\/","article_published_time":"2021-04-07T09:53:09+00:00","article_modified_time":"2022-03-21T12:16:42+00:00","author":"Prepbytes","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Prepbytes","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/prepbytes.com\/blog\/commonly-asked-interview-questions-on-c\/#article","isPartOf":{"@id":"https:\/\/prepbytes.com\/blog\/commonly-asked-interview-questions-on-c\/"},"author":{"name":"Prepbytes","@id":"http:\/\/43.205.93.38\/#\/schema\/person\/3f7dc4ae851791d5947a7f99df363d5e"},"headline":"Commonly asked interview questions on c","datePublished":"2021-04-07T09:53:09+00:00","dateModified":"2022-03-21T12:16:42+00:00","mainEntityOfPage":{"@id":"https:\/\/prepbytes.com\/blog\/commonly-asked-interview-questions-on-c\/"},"wordCount":774,"commentCount":0,"publisher":{"@id":"http:\/\/43.205.93.38\/#organization"},"articleSection":["C Programming"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/prepbytes.com\/blog\/commonly-asked-interview-questions-on-c\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/prepbytes.com\/blog\/commonly-asked-interview-questions-on-c\/","url":"https:\/\/prepbytes.com\/blog\/commonly-asked-interview-questions-on-c\/","name":"Commonly asked interview questions on c | C Programming | PrepBytes Blog","isPartOf":{"@id":"http:\/\/43.205.93.38\/#website"},"datePublished":"2021-04-07T09:53:09+00:00","dateModified":"2022-03-21T12:16:42+00:00","breadcrumb":{"@id":"https:\/\/prepbytes.com\/blog\/commonly-asked-interview-questions-on-c\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/prepbytes.com\/blog\/commonly-asked-interview-questions-on-c\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/prepbytes.com\/blog\/commonly-asked-interview-questions-on-c\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"http:\/\/43.205.93.38\/"},{"@type":"ListItem","position":2,"name":"C Programming","item":"https:\/\/prepbytes.com\/blog\/category\/c-programming\/"},{"@type":"ListItem","position":3,"name":"Commonly asked interview questions on c"}]},{"@type":"WebSite","@id":"http:\/\/43.205.93.38\/#website","url":"http:\/\/43.205.93.38\/","name":"PrepBytes Blog","description":"ONE-STOP RESOURCE FOR EVERYTHING RELATED TO CODING","publisher":{"@id":"http:\/\/43.205.93.38\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"http:\/\/43.205.93.38\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"http:\/\/43.205.93.38\/#organization","name":"Prepbytes","url":"http:\/\/43.205.93.38\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"http:\/\/43.205.93.38\/#\/schema\/logo\/image\/","url":"https:\/\/blog.prepbytes.com\/wp-content\/uploads\/2025\/07\/uzxxllgloialmn9mhwfe.webp","contentUrl":"https:\/\/blog.prepbytes.com\/wp-content\/uploads\/2025\/07\/uzxxllgloialmn9mhwfe.webp","width":160,"height":160,"caption":"Prepbytes"},"image":{"@id":"http:\/\/43.205.93.38\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/prepbytes0211\/","https:\/\/www.instagram.com\/prepbytes\/","https:\/\/www.linkedin.com\/company\/prepbytes\/","https:\/\/www.youtube.com\/channel\/UC0xGnHDrjUM1pDEK2Ka5imA"]},{"@type":"Person","@id":"http:\/\/43.205.93.38\/#\/schema\/person\/3f7dc4ae851791d5947a7f99df363d5e","name":"Prepbytes","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"http:\/\/43.205.93.38\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/232042cd1a1ea0e982c96d2a2ec93fb70a8e864e00784491231e7bfe5a9e06b5?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/232042cd1a1ea0e982c96d2a2ec93fb70a8e864e00784491231e7bfe5a9e06b5?s=96&d=mm&r=g","caption":"Prepbytes"},"url":"https:\/\/prepbytes.com\/blog\/author\/gourav-jaincollegedekho-com\/"}]}},"_links":{"self":[{"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/posts\/2654","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/users\/52"}],"replies":[{"embeddable":true,"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/comments?post=2654"}],"version-history":[{"count":5,"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/posts\/2654\/revisions"}],"predecessor-version":[{"id":8121,"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/posts\/2654\/revisions\/8121"}],"wp:attachment":[{"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/media?parent=2654"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/categories?post=2654"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/tags?post=2654"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}