C Interview Questions

Several jobs require candidates to have a profound knowledge of C. These C Interview Questions have been designed specially to get you acquainted with the nature of questions that you may encounter during your interview for the subject of C.

1. What is C language?

C is a procedural and general-purpose programming language created by Dennis Ritchie in 1972 at the Bell Telephone Laboratories. It was invented to write UNIX operating system. C is the most widely used computer language. The main features of C language include low-level access to memory, easy to learn and modular structure which makes code debugging, maintenance, and testing easier. Due to these features make C language suitable for system programmings like an operating system or compiler development.

2. What are the features of C Programming Language?

Some important features of C programming language are given below:

• Simple Language - C is a simple language. It is very easy to understand and learn.
• Mid-Level Language – C is a mid-level language and enables low-level language featuress like development of system applications such as kernel and drivers. It also supports the feature of high-level language. Hence C is a mid-level language.
• Machine Independent Language – C can be interpreted on various operating systems including UNIX-based systems, Linux, Mac OS and various versions of Windows.
• Case-Sensitive Language - C is a case sensitive language and treats the uppercase and lowercase characters in a different manner.
• Structured Programming Language – C is a structured programming language that means any C program can be achieved in parts using functions. This makes any C program easy to understand and modify.
• Rich Library Support – C provides lots of inbuilt functions which makes programming faster and easier. These functions can be accessed by including appropriate header file in the C program.
• Powerful & Fast Language - C is a fast language as it takes very less time in compilation and execution.
• Dynamic Memory Allocation - C supports the use of pointers which means a user can directly interact with memory and allocate memory dynamically.

3. What is a pointer in C?

A pointer is a variable which stores address of another variable.The address of a variable can be obtained by using ampersand sign (&), known as address-of operator followed by the name of a variable.

The value of a variable can also be accessed by using pointer. The * operator, known as dereference operator followed by the name of the pointer gives the value stored in the address pointed by the pointer.

//p1 is a pointer which stores address of variable
p1 = &Var;

//*p1 gives value of variable
x = *p1;

In the example below, an integer variable called MyVar and a pointer called p1 are created. pointer p1 is assigned the address of MyVar. Then, *p1 is used to get the value of MyVar as shown in the output.

#include <stdio.h>

int main (){
int MyVar = 10;
int *p1;
p1 = &MyVar;
printf("%p\n",p1);
printf("%i",*p1);
return 0;
}

The output of the above code will be:

0x7ffed13c2db4

10

4. Write a program to swap two numbers without using the third variable.

This are many ways to swap two numbers. The example below uses + operator to swap two numbers.

#include <stdio.h>

static void swap(int, int);

static void swap(int x, int y) {
printf("Before Swap.\n");
printf("x = %i\n", x);
printf("y = %i\n", y);

//Swap technique
x = x + y;
y = x - y;
x = x - y;

printf("After Swap.\n");
printf("x = %i\n", x);
printf("y = %i\n", y);
}

int main() {
swap(10, 25);
}

The output of the above code will be:

Before Swap.
x = 10
y = 25
After Swap.
x = 25
y = 10

5. Write a program to print Fibonacci series.

This are many ways to print the Fibonacci series in C. The example below uses dynamic programming to print the given term of Fibonacci series.

#include <stdio.h>

static int fib(int);

static int fib(int n) {
//creating array which contains Fibonacci terms
int f[n+1];
f = 0;
f = 1;
for(int i = 2; i <= n ; i++)
{
f[i] = f[i-1] + f[i-2];
}
return f[n];
}

int main() {
printf("Fibonacci 6th term: %i\n",fib(6));
printf("Fibonacci 7th term: %i\n",fib(7));
printf("Fibonacci 8th term: %i\n",fib(8));
}

The output of the above code will be:

Fibonacci 6th term: 8
Fibonacci 7th term: 13
Fibonacci 8th term: 21

5
{"ft_lang_label":"__label__en","ft_lang_prob":0.8900862,"math_prob":0.9197166,"size":4312,"snap":"2022-05-2022-21","text_gpt3_token_len":1033,"char_repetition_ratio":0.12766945,"word_repetition_ratio":0.048648648,"special_character_ratio":0.2588126,"punctuation_ratio":0.12748538,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9740378,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2022-01-27T08:37:28Z\",\"WARC-Record-ID\":\"<urn:uuid:f11e0537-eb78-4715-af1f-ce560860d1e1>\",\"Content-Length\":\"22979\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:526ef880-96c3-475a-a899-5f990013693b>\",\"WARC-Concurrent-To\":\"<urn:uuid:71cde9ab-bd10-44b7-972b-0916de5aa9fa>\",\"WARC-IP-Address\":\"35.192.153.103\",\"WARC-Target-URI\":\"https://www.alphacodingskills.com/interview/c-interview-questions.php\",\"WARC-Payload-Digest\":\"sha1:YGASLWR4EVFSFXXC2OLSHPBEQWYUB53Z\",\"WARC-Block-Digest\":\"sha1:Q25SL5URNPVOCAHLS3W4WEODYC27FFCN\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2022/CC-MAIN-2022-05/CC-MAIN-2022-05_segments_1642320305242.48_warc_CC-MAIN-20220127072916-20220127102916-00442.warc.gz\"}"}