0% found this document useful (0 votes)
3 views6 pages

C Programming Interview Prep Questions 1

The document is a comprehensive guide for C programming interview preparation, covering topics such as data types, operators, conditionals, loops, functions, arrays, recursion, pointers, strings, and memory management. It includes numerous programming exercises and examples to illustrate key concepts and techniques. Additionally, it addresses advanced topics like dynamic memory allocation, storage classes, and command line arguments.

Uploaded by

raomkrd
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views6 pages

C Programming Interview Prep Questions 1

The document is a comprehensive guide for C programming interview preparation, covering topics such as data types, operators, conditionals, loops, functions, arrays, recursion, pointers, strings, and memory management. It includes numerous programming exercises and examples to illustrate key concepts and techniques. Additionally, it addresses advanced topics like dynamic memory allocation, storage classes, and command line arguments.

Uploaded by

raomkrd
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

C Programming Interview Prep Questions

C Programming Interview Prep Questions

Basics Refresher

Datatypes

What is the size of int in C for different platforms? Is it same?

What is the size of integral & real types in C?

How do you ensure that size of datatypes is same across platforms?

How does a char get stored?


Note: Show some programs illustrating char storage and printing
What is ascii value of 0 & 5
What is ascii value of a & d, A & d
What is ascii value of '\0' & \n'
What is ascii value of ' ' (Space)

Qualifiers 1

How is signed and unsigned int stored? What is the range?


What is const keyword?
Explain register keyword?

Operators

Arithmetic Operators

What is the difference between pre and post increment? Show examples.

Logical Operators

Overview & few code snippets.

Bitwise Operators

Overview of bitwise operators


Get, Set, Clear bit
Get, Set, Clear nth bit
Get, Set, Clear N bit
Macros for above operations
Toggle bit(s)

What is practical use of XOR (^)?


WAP to print bits
WAP to count the number of set bits (Count 1's)
WAP to count number of 0s in a number
WAP to check whether number is Even or odd using bitwise operators
WAP to reverse the bits in an integer
WAP to check whether a number is power of 2 without loops

Ternary Operator
Usage and example.
WAP to find largest of 2 nos using ternary op
WAP to find largest of 3 nos using ternary op

Conditionals & Loops

Switch case
Explain switch case with an good example

Programs

Pattern program 1
5
54
543
5432
54321

Pattern program 2

*
* * *
* * * * *
* * * * * * *
* * * * * * * * *

Ref: https://www.programiz.com/c-programming/examples/pyramid-pattern

WAP to multiple two numbers (m x n) without using multiplication operator

WAP to reverse a number

WAP to convert decimal to hex

What is the o/p of the code?

int main ()
{
int i = 1, j = 1;
for (--i && j++; i < 10; i += 2)
{
printf ("loop ");
}
return 0;
}

break & continue


Overview & examples
WAP to check whether a number is prime or not using break
Example of nested loop with break

Typecasting

Explain typecasting with useful examples

Overflow/Underflow

What is overflow and underflow in integers

Pointer Basics

Overview of basic pointer rules.


What is the use of pointers.

Note: Discuss more concepts including void pointer, NULL pointer, Dynamic memory allocation, Double
pointer, const pointer, Endianess etc in Part 2

Functions

What is the difference between pass by value and pass by reference. Show examples.

WAP to swap two integers


WAP to swap two integers without using temp variable
WAP to find product of 2 numbers using pass by reference
WAP to find sum and product of 2 numbers using pass by reference (Extension of previous program)

Arrays

Quick refresher of arrays.

How to pass arrays to functions

Array Programs (Use functions)


WAP to find the largest and smallest number in an array
WAP to find the second largest number in an array
WAP to remove duplicates in an array. Return a new array without duplicates and size of new array.

Recursion

Explain recursion with examples.

WAP to generate Factorial series using recursion


WAP to generate Fibonacci series using recursion

Add some What is the o/p type questions

Storage Classes & Memory Segments

Explain below with good code examples


What is the difference between local and global variable.
Q: Can a local variable's address be returned?
What is the difference between local and static local variable.
What is the difference between global and static global variable.

Describe Memory segments in brief


Avoid explaining command line arguments, program header etc. Just explain CS, DS, BSS, Stack and
Heap

Scope and Lifetime of variables.

What is the use of extern keyword. Show usage of extern of variables and functions with simple
examples.
Q: What is a static function?

What is a block variable?


Summarize storage classes.

Strings

Overview of string

WAP to read your name and print it


Note: use scanf("%s", name);

How to pass strings to function?

WAF to prints a string:


void myputs(char *str);
void myputs(char str[]);

WAF to find length of a string


WAF to check whether a string is palindrome or not
Solution: https://drive.google.com/file/d/1luXPRa98IidFifuqnsQYDR6Ula2lYsGK/view?usp=share_link
WAF to reverse a string
WAF to implement strcpy, strcat

Q: Explain the difference between:


char str1[10] = "Hello";
char *str2 = "Hello";

Q: Have a look at this code


char str1[10] = "Hello";
char *str2 = str1;
*str2 = 'P';
str[1] = 'i';
puts(str2);

Will this code give a segfault. Why?

Why is scanf/gets not recommended to use. Why is fgets recommended. Usage of fgets

Pointers 2

Explaining remaining pointer rules

Dynamic memory allocation


Explaining Dynamic memory allocation briefly using malloc and free
Explain calloc and its difference with malloc
What is realloc?

WAP to allocate an integer array of size n. Store values in the array and find its sum.

Void Pointer

What is void pointer. Show usage of void pointer


WAP to Implement a generic swap function using void pointer

const pointer

Difference between const char *ptr and char * const ptr


What about const char * const ptr

More topics

What is segmentation fault?


What is a dangling/wild pointer?

2D Array

Basics of 2D arrays
Creation and access
How to pass 2D array to functions
How to Dynamically allocate 2D array of size m x n (Show only both dynamic method)

Array of strings & Command line arguments

How to define and access array of strings


Command line arguments usage

WAP to find the sum and average of command line args

You might also like