Tag Archives: C Programming

Can you Learn C++ without Learning C

I can answer this question straight away by either saying a ‘Yes’ or ‘No’. But, by simply saying a ‘Yes or No’ won’t justify the answer. It all depends upon the ability of the person who is learning C++. But, it can end up like you learn to drive an automatic car without knowing the manual driving lessons. When circumstances arrive, you may have to simply say “I don’t know”. Therefore, it is always better if you learn the basics rather than moving ahead baseless. After all, C++ is just an improvement on C. Now, let me help you with all the points that will add more justification, comparison, and reason. Let’s navigate through these points. 

Why should you learn C?

Learning C programming has a lot of benefits. But first, you need to understand the underlying architecture of how things work with C is very important. 

C was initially developed by Dennis Ritchie between 1969 and 1973 as a procedural programming language. The main purpose of developing this system programming language was to write an operating system. Some of the features which make C language suitable for system programmings like an operating system or compiler development are its: 

  • Low-level access to memory
  • A simple set of keywords
  • and a Clean style

Like in the case of learning to drive an automatic and manually driving car, if you know to drive a manual car, it will make driving an automatic car all the easier. Similarly, if you learn C programming first, it will help you to learn any modern programming language very well. 

Advantages of Learning C 

  • C language helps you to understand the underlying architecture of an operating system like pointers, working with memory locations, etc.
  • C can be called as a middle-level language, because, it combines all the features of Low-Level machine-understandable assembly languages and High-Level user-friendly languages. Language C reduces the gap between the low-level and high-level languages and can be used for writing operating systems as well as doing application-level programming.
  • It allows you to develop portable and firmware applications. The C language was developed with an objective of writing system software and therefore, it is ideal for developing firmware systems.
  • Learning C language first helps you to understand the fundamentals of Computer Theories like Computer Networks, Compiler Designing, Computer Architecture, and Operating Systems. If you’re working on these theories, it requires a good knowledge of C programming. 
  • Also, C helps you to understand machine-level details. So if you want to work as a networking engineer or a system administrator, learning C language is a must to work with CPU cache, memory, and network adapters. 
  • Learning C is easy as it has fewer libraries in comparison with other high-level languages. It will clear out programming concepts to a great extent as in C you have to write a lot of things from scratch. This will not only help in building your analytical skills but will learn to implement some basic operations all your own. 
  • Programs written and compiled in C can be executed faster than other programming languages. Also, not having any additional processing overheads such as garbage collection or preventing memory leaks, etc makes C more advantageous. While a programmer must take the initiative to do all the things his own. 
  • C uses embedded programming extensively where it is used to control micro-controllers such as auto-motives, Robotics, Hardware, etc.
  • C creates a list of instructions for a computer to follow and therefore it is easy to learn the language. 

Key Differences between C and C++

C++ language is a subset of the C language and was first designed as an extension of C. 

When C has procedural language features, C++ has both procedural and object-oriented programming features like polymorphism, inheritance, abstraction, encapsulation, etc.

Best C/C++ IDEs

C and C++ are very popular and actively used across various applications and systems worldwide. Both languages are still actively used by most programmers because of the powerful set of features and the excellent security of C++. One of the best things about C++ is its IDE or the Integrated Development Environment. This environment offers the developers a digital environment to develop software, hardware and games with the built-in function like code completion, integration, debugging, and all the way to compiling and syntax highlighting. During the year 2020 and beyond, the developers will have some of the top and the best C++ IDE’s. Some of these C++ IDEs can also be used for C programming. They are:

Eclipse- An easy-to-use powerful IDE that offers open-source utility and functionality. It is also one best C++ IDE for Windows Applications. 

Code:: Blocks- It is a free C/C++ IDE that has all the features to meet the demands of the C and C++ developers. This IDE can be used on Windows. 

GNAT Programming Studio-  Also known as GPS, GNAT Programming Studio is a highly advanced Free IDE that simplifies the interaction between the software and its developers. 

Visual Studio Code: Developed by Microsoft and based on an Electron framework, Visual Studio Code is an open-source IDE designed for Windows, macOS, and Linux. It is the most popular developer environmental tool and best IDE among others with excellent customization options. 

Similarly, other popular and the best C++ IDE for Windows, Linux, and Mac OS X are CodeLite, Dev C++, Qt Creator, Sublime Text, Linx, MonoDevelop, CLion, Anjuta, and C++ Builder

If you have the willingness to learn C or C++ languages regardless of whether you’re just a beginner or a C or C++ Programmer, IDEs are best to make your programming career easy. 

C++ Compilers

C++ Compilers are necessary when you start doing a specific program as it will make your job easier and for computers to understand the input given. There are too many C++ compilers which can be recommended that are either available for free or for a price. The higher the prices, it will reflect in the features offered to you. 

While the C++ world is just too large and too much new is happening, you will require a C++ certification to fight the competition in the industry. 

Features & Properties of C

  1. Procedural
  2. System programming language
  3. Does not support classes and objects
  4. Bottom-up approach
  5. Supports pointers

Features & Properties of C++

  1. Object-oriented
  2. Faster Execution and Speed
  3. Rich library support in the form of the standard template library
  4. Supports Pointers & References
  5. Bottom-up approach
  6. Compiled

Although C++ is much more advanced and superfast than C if you want to make your journey easier to start from the basics. It will help your learning not only C++ but also any other languages easier. So, let’s start from the beginning with an extremely simple C program and build up from there. There are numerous benefits of learning to c/c++ language for your career. It is recognized worldwide and used in a multitude of applications. It will help you secure a great career in the future. 

Spread the love

Stack Interview Questions

The stack is always a favourite part of the interviewer in any programming interview. Stack has an important place in Linear data structure and used to implement complex solutions. Stack Interview Questions are the best collection of concepts and questions asked in the data structure Interview.

Stacks are important part of data structures and comes under abstract data structures. They allow access to only one data item at a time and that is the last item inserted.

Since internally other data structures are used by stack, they are abstract data type. Stacks use array. Stacks are useful to perform many operations in other data types.
Few examples of Stack implementation:

  • Stack is used by Binary trees in traversing of nodes.
  • Stack is used by Graphs in searching the vertices of the graph.
  • Stacks can be used to process tasks, messages etc.

To crack Stack interview and to give perfect answers to stack interview questions and answers, It is very important to have basic concepts of stack and other data types like array.

Here we have given the basic concept of stack and implementation of stack using C language.

While keeping in mind the practical implementation and complexity we have given plenty of examples of stack implementation and operations using C Programming.

What is a Stack?

A stack is a linear data structure and represented a list of the element in which an element may be inserted or deleted only from one end, called the top of the stack.

Elements in the stack are arranged in a linear fashion. Unlike an array, we can not access an element randomly.

According to the behaviour of Stack, we can have two important operations

  1. PUSH and
  2. POP

Insertion of an element in the stack from the top is called PUSH and removal of an element from the stack is called POP.

We can only access the last element inserted in a Stack. Hence We can say an Item can either Inserted or Deleted At only one end of the stack and that end is the TOP. This is why We called it a LIFO – Last In First Out.

Main Features of Stack

  1. The stack is a Linear type data structure
  2. Allow only the last element to access
  3. Random access of element is not allowed
  4. The stack is an ordered list of similar data type
  5. When a stack is completely full it is called Overflow Stack and If completely empty it is called Underflow Stack.
  6. A stack is a recursive data structure. Here is a structural definition of a Stack:
    1. a stack is either empty or
    2. it consisted of a top and the rest which is a stack;

Application of Stack

  • We can use stack reverse a string. You push a given string to stack – character by character – and then POP character from the stack.
  • Undo Operations in the text editor is an application of stack PUSH and POP.

Basic Operations on Stack

Stack allowed the following operation with data stored it with:

  1. Push operation
  2. Pop operation
  3. Peek operation
  4. isFull
  5. isEmpty

Algorithm for PUSH Operation in Stack

Consider MAX represents the last position of the element to be inserted and TOP is the current position. TOP initially points to 0.

Algorithm POP Operation in Stack

The function will return the popped value from the stack

Implementation of Stack

The stack can be implemented as

  1. Using Array
  2. Using a Linked list

Array and linked list both are used to implement a stack. Both have some advantages and disadvantages associated with them. Here are some relative comparisons between these two.

  • The array is a collection of similar data types elements while the linked list is a collection of elements of the same type connected to each other by pointers.
  • Array consumes memory in a contiguous manner. Also, the size of array is decided at compile time. This kind of memory allocation is called Static memory allocation. But in case of linked list memory allocated at runtime. The size of the list can be increased or decreased at runtime. This kind of memory allocation is called dynamic memory allocation.
  • The size of the array is fixed. Memory allocated as soon as the array is declared. In the case of a linked list, size can grow or shrink. 
  • In array, due to memory allocation in contiguous in manner, insertion and deletion take more time in comparison to linked list.
  • Accessing an element in an array is faster. Also, any element of an array can be easily accessed by using indexing. This is not in the case of a linked list. You have to transverse from the starting point to access any element.


Implement Stack using an Array

A working Example of Implementation of Stack using Array

Implement Stack using a Linked list

A working Example of Implementation of Stack using Linked List

Spread the love

Binary Search Tree Data Structure

A tree is best thought of in this sort of picture. You have a root node at the very top and it has child nodes and each of those child nodes, they have child nodes themselves, and so on.

Very often when we’re talking about trees we talk about binary trees. 

Binary Tree 

A binary tree means that each node has no more than two child nodes. 

That is that each node has a left node and a right node. Of course one or both of those could also be null.      

Binary Search Tree

A binary search tree is a binary tree that fulfills a specific ordering property and a special tree data structure. So on any subtree, the left nodes are less than the root node which is less than all of the right notes. This ordering property makes finding a node very fast because we have a pretty good idea of where it would be. 

How Searching Works Binary Search Tree?

Let’s choose a node, it’s bigger than the root node, so let’s go to the right. Now the next node, if it’s smaller than that node so it must be on the left unless it should be in right. And so very quickly we can start to zoom in on where that node will be because at each operation we’ve chopped off hopefully about half of the nodes and very quickly we find the node we’re looking for. 

Inserting an Element

Inserts work much like finding an element works. We start with some element we want to insert like say, 19, and we say is it bigger or smaller than the route? 

Let say, it’s bigger so let’s go to the right. Now compare it to the next node? If it’s smaller so let’s go to the left. We will do this over and over again until we get to an empty spot or a null node and then we say ok that’s where we should insert our new element. 

Now the one problem here is that if we get elements in a particular order, we could get really imbalanced. Suppose we have a new binary search tree and we just follow the properties of insertion.

So we insert 1 and then 2 to it’s right and then 3 to it’s right and 4 to it’s right, we’re going to get this data structure that looks less like a tree and more like a long list.

 And then inserts and finds will no longer be so fast. There are some algorithms that can ensure that our tree stays balanced, that is roughly the same number of nodes will be on the left side of the subtree and on the right.

These algorithms get pretty complicated so we’re not gonna go into the details here, but it’s worth knowing that they’re built into a lot of programming languages and in a lot of cases and Data Structures Interview Questions you’ll just assume that you have a balanced tree. 

Traversing Through a Tree

The last operation to talk about is traversing or walking through a tree. So there are three common ways we walk through a tree we can do an 

  1. Inorder traversal
  2. Preorder traversal
  3. Postorder traversal. 

A Preorder traversal means that you visit the root first and then you visit it’s left nodes and it’s right nodes. 

In Inorder traversal, you visit the left nodes first then the current node and then you go to the right nodes. 

In a Post Order Traversal, the root node comes up last so you visit the left nodes and then the right nodes, then the current root node. 

Typically in binary search trees, we want to do in order traversals because that actually allows the nodes to be printed in order. 

Implement A Binary Search Tree

Spread the love

Embedded using C Interviews Questions and Answers

What is an Embedded system? Describe Embedded C.

In simple words, the Embedded system can be referred to as customizing hardware with customizing the software. Embedded systems are controller-based which is embedded with software to perform specific tasks.

Embedded C is an extended version of C language which is used to develop microcontroller-based systems.


What are little endian and big endian types of storage? How can you identify which type of allocation a system follows?

Big-endian and little-endian are two formats to store multibyte data types into the computer’s memory. Big-endian format and little-endian format. In Big-endian format, MSB(most significant byte) gets memory first and LSB (least significant byte) in last.

In the case of little-endian format the LSB byte gets memory first and MSB byte in last.

Suppose an integer having value 0x12345678.

In the case of big-endian 0x12 gets stored first in memory, then  0x34, then 0x56 and in the last 0x78.

In the case of little-endian 0x78 gets stored first in memory, then  0x56, then 0x34 and in the last 0x12.

0x12 0x34 0x56 0x78
0x2000 0x2001 0x2002 0x2003 0x2004
Memory address
Big Endian Format
0x78 0x56 0x34 0x12
0x2000 0x2001 0x2002 0x2003 0x2004
Memory address
Little Endian Format


Write a C program to identify little and big endian.

#include <stdio.h>

int main ()


 unsigned int x = 0x12345678;

 char *c = (char*) &x;

 if (*c == 0x78)


   printf (“Architecture is little endian. \n);




    printf (“Architecture is big endian. \n);


 return 0;



What is ISR(Interrupt Service Routine)?

ISR refers to the Interrupt service routine. Whenever an interrupt occurs, the controller completes the execution of the current instruction and starts the execution of an Interrupt Service Routine. This process is also known as an interrupt handler.  


What is a Qualifier in C?

Qualifiers are the keywords which are used to modify the values of variables. There are two types of the qualifier in C.


Const qualifier used with a variable when we want to make variable to unchangeable. If you will try to change, the compiler will give you an error.


Variable qualified with volatility prevents the compiler to optimize that variable. The values of the variable can be changed by code outside the scope of the current code at any time. The system always reads the current value of a volatile object from the memory location rather than keeping its value in a temporary register.


What is a ‘volatile’ variable, can a variable be both constant and volatile, can a pointer be volatile?

Consider the following example:

volatile int x;

When the compiler finds the variable qualified with the volatile qualifier, it clearly comes to know to the compiler that it will not be involved in any change related to the variable. The value of this variable can be changed anytime by any external source.

A single variable can be const as well as volatile. Example

int volatile *const y;

y is a constant pointer to a volatile integer.

Yes, volatile pointers are possible in c.

int *volatile value;


What is interrupt latency? How to reduce interrupt latency?

Whenever a microcontroller receives any interrupt, first it completes currently executing the instruction , then provides service to interrupt and again continues the executing instruction from the same position where the controller skipped.

So, it takes some time to microcontroller to provide service to interrupt. The amount of time(Number of cycle) taken by microcontroller to start servicing to interrupt known as interrupt latency.

Interrupt latency can be minimized by writing short ISR routine and by not delaying interrupts for more time.


Can we use any function inside the ISR?

Yes, we can but doing so will increase interrupt latency. That’s why it is not recommended as in many cases latency should be as small as possible and using a function inside the ISR will also decrease performance.


What are storage classes?

Storage classes used to classify variable as per their scope (visibility) and  lifetime. Default value and storing value place also different to each other. There are four types of storage classes.


Variable Scope Lifetime Default Value
Auto Local Within the function Garbage value
register Local Within the function Garbage value
Static Local Till the end of the program Zero
extern Global Till the end of the program Zero

Note: Only register variables get memory in a CPU register (if CPU register has vacant memory). Other three variables get memory in RAM memory locations.


What is use of static keyword?

Static keyword can be used with variable as well as functions. The life of static variable lasts till the end of the programs and scope is local(Visible within the function only). Still static variable holds  their value after they are out of their scope.


int increment()


 static int count = 0;


 return count;



int main()


 printf(“%d “, increment());

 printf(“%d “, increment());

 return 0;


Output: 1 2

Function with static within any source file can accessible to only that source file.By using static we make function local only to source file within it is defined.


What is use of register storage class?

In register storage class CPU registers are used to store values.

for example. If you want to store variable which will be frequently required then you can store it in the register like in case of loops. However it is not guaranteed that variable will get store in register.

It is like a request to CPU to allow the variable to store in CPU’s register.

If CPU has vacant register to store variable ,it permits otherwise ignore the request and variable gets allocated in ram memory.

Note: We cannot obtain the address of a register variable using pointers.


What is Synchronous and asynchronous data transmission?

Serial data communication has two types.

Synchronous data transmission

Synchronous transmission needs a clock signal between the source and target to let the target know of the new byte.synchronous transmission data is transmitted in the form of data bundles. So data rate of it very high.

Asynchronous data transmission

Asynchronous transmission has no need of clock signal between the source and target. It sends start and stop bit to start and stop the transmission. It send single-byte data at a time so data rate of it is not much good.

Synchronous vs. Asynchronous Transmission

  1. In synchronous mode, data is transmitted in the bundle but in asynchronous mode, data is transmitted byte by byte.
  2. Synchronous required a clock signal between the source and destination to acknowledge the destination about information while in asynchronous clock signal is not required.
  3. Data transfer rate of synchronous is faster compared to asynchronous .
  4. Synchronous mode has lower overhead compared to asynchronous transmission.


What is Baud Rate? How it differs from Bit Rate?

In data communication, data are transferred along with signal. The number of the signal transferred per second is known is Baud rate. Bite rate is a number of bits (data) transferred per second. As a single signal may contain more than 1 bit while transferring the data. The relation between the two is given below.

Bit rate = baud rate x the number of bit per baud


What is memory leak ? How we can avoid it?

The memory leak is a condition where the programmer allocates memory in the heap area by using dynamic memory allocation and forget two deallocate. So, it is recommended to use the free() function to deallocate memory which is allocated by dynamic memory allocation once the use of memory location is not further needed.


How to set, clear and toggle a single bit of variable?

The value represents the initial variable and position represents the position of bit in a variable.

Setting a Bit:

Value |= (1 << position)

Clearing a Bit:

Value &= ~ (1<<position)

Toggling a Bit:

Value ^= (1 << position)


What is Dynamic Memory Allocation(DMA)? What is the difference between malloc() and malloc()?

Dynamic memory allocation (DMA) is the process of allocating memory for variables at run time of the program. This kind of allocation allocates memory in the heap area of memory.

malloc function takes one argument at calling but calloc takes two arguments. Also, memory allocated by calloc is initialized with zero.

These functions always return pointer of type void which can be cast into a pointer of any form.

Syntax: For 5 element of int type variable. ptr is int type pointer.

ptr = (int *) malloc (5*sizeof(int))

ptr =  (int*) calloc (5, sizeof(int))


What are void pointers in C?

Void pointer also known as generic pointers. There is no data type associated with these, so these can be typed cast to any type.


What is a dangling pointer?

A pointer pointing to deleted or deallocated memory  location is known as dangling pointer. To try to access this type of pointer causes undefined behavior or segmentation fault.


What is a wild pointer?

An uninitialized pointer is known as a wild pointer. When we declare any pointer without giving any address, it shows an arbitrary memory location. As we assign it a memory location, it is not a wild pointer anymore.


int main()


           int a;

           int* ptr;              //Wild pointer

           ptr = &a;           //Not more wild pointer




Explain the meaning of these pointers?


  • int *ptr;
  • cons int * ptr;
  • int * const ptr;
  • const int *const ptr;


int *ptr

It is a pointer to a variable. We can change the value pointer pointing to and also the value of ptr.


const int * ptr

It is a pointer to a constant.  It can be also declared as int const *ptr. We can change the pointer to point other variable but we can not change the value of it by using the pointer.


int * const ptr

It is a constant pointer to a variable. We can change the value of the variable by using pointer but we can not change the pointer to point other variables.  


const int *const ptr

It is a constant pointer to a constant variable. Neither we can change the pointer to point other variable nor we can change the value using the pointer.


Spread the love

C Programming Interview Questions and Answers

What is the purpose of printf() and scanf()?
printf () and scanf() are the two main functions in C Language that can be used to send output and receive input from the standard output and input respectively. They are defined in stdio.h

How to check equality between two variable in C language?
In C language the operator “==” is used to check equality of two values, while the symbol “=” is used for assignment. For example the expression: y==x will be evaluated to either 0 or 1 (depending on the actual value of x and y), while the expression y=x will assign y the value of x.

What is meant by increment operators in C?
In C language there is a short way of incrementing (++) or decrementing (–) a variable by 1. These operators are called increment operators. They can have the form of prefix (e.g., ++x) or postfix (e.g., x++).

What will be the value of the variable y in the following expression:
The value of y will be 12, since the old value of x (here 7) will be added to 5 before x is incremented.

Write down the output of this C program:

int main(){
   int x, y;
   printf("x=%d,  y=%d\n", x,y);
  return 0;

The output will be:
x=15, y=15

What are the two operators that used in dynamic memory allocation in C?
malloc() and free(). The function malloc() can allocate a block of memory dynamically, while free can free this block.

How arrays are declared in C language?
Arrays in the C language are declared by giving the data type following by the variable name and finally the array size in two brackets. For example the expression:

int x[10];

declares an array called x of type integer with 10 elements.

Can two C structures added together using the plus operator?
no, in C language you cannot apply arithmetic operators directly on the structure. Instead, you will need to manipulate the structure element individually.

What is mean by function declaration and function definition in C language?
In C language , the function can be first declared to tell the compile about its signature. This will allows such functions to be called in program position before its actual definition. However, function definitions involve writing exactly what this function should do when it is executed.

How structures are declared and defined inside the C language?
Structures in C languages are usually declared by the word struct followed by the name of the structure. The elements of the structure are enclosed in curly brackets and the structure definition is terminated by a semicolon at the end. For example, the following lines are an example for declaring a structure called Point:

struct Point{
   int x;
   int y;

In C language, after a structure is declared it can be used after words by writing the word structure followed by the variable name, for example:

struct Point p1;

What is the purpose of C pre-processors in the C languages?
In C language the pre-processors directives are not part of the compiler, instead they instruct the compile to perform certain operations at compile time. For example, the include directive (#include) is used to ask the compile to include a header file to the currently compiled code.

How to declare an array of 100 integer values in C?
This can be declared as:

int a[100];

How to pass an array of type float to a Function?
Array can be passed to functions in many ways. For example they can be passed to functions as a pointer, for example:

void somefunc(int*a);

or as a sized array:

void somefunc(int a[10]);

It can also be passed as upsized array:

void somefunc(int a[]);

In this last approach, we will need to pass the array size as a seprate variable.

Declare a two dimensional array in C of size 10×50
It can be declared as follows:

int a[10][50];

The first parameter in brackets will represent the number of rows while the second parameter will represent the number of columns.

Describe the difference between for and while loops in C language.
In C language, as well as in many other computer languages, for loops can be used when the beginning and end of the loop is definitely known. In this case, it will be very convenient to use for loop. However, if we do not know exactly the start and end of the loop, we can use while loop instead.

What is meant by recursion in C language?
Recursion simply means a function that calls itself. In can view viewed as an alternative approach for using loops. All the calling parameter of the function is stored in the stack. The values are kept until the function is returned. A function that is used in a recursion should continue a trivial condition will stop the recursion from repeating forever. Otherwise and infinite loop could happen.

  1. Which of the following is not a logical operator in C language:
  2. ==,
  3. |= ,
  4. &&

The operator |= is not a logical operator. It is used as a combination of bitwise or and assignment operators.

What is the meaning of a pointer variables in C language?
In C language, a pointer variable is a variable that point to an address in memory. This is an efficient way in C language in order to access variable addresses from different locations in the program code.

Consider the following C program:

int main(){
   int x=7;
   int *px;
   printf("x=%d", x);
   return 0;

What will be the output of this program?

What is the purpose of the function sizeof() in C language?
The sizeof() in C language is used to calculate and return the size of variable and data types.

When one should use do while loop in C language?
Do while loop is used in C language to repeat the loop at least one time before the loop condition for termination. Therefore it is very helpful in certain scenarios where we need to execute the code at least one time before deciding to terminate or not.

What is the difference between const pointer and pointer variable in C language?
const pointers are defined in this way:

int *const ptr;

They can be used to refer to the address of other variables like this
However, what we cannot do using const point is the increment operator. In other words, we cannot write something like this:
In contrast, pointer variables can be modified by either ways.

How to allocate dynamic two dimensional arrays in C language?
There are many different ways to dynamically allocate two dimensional arrays. May be the best way is to tread them as static arrays by allocating rows of pointers and each row is then assigned to a dynamic array representing the columns. So we can do it in these steps:

int** a;     
/*assume this array is of type int*/

/*rows represent the number of rows in the array*/
if(a==NULL) return;                            
/*make sure the memory is correctly allocated for rows*/
int i;
for(i=0;i&lt; rows; i++)
/*allocate memory for each row*/

/*TODO: make sure memory is correctly allocated*/

What is the meaning of ternary operator and how can it be used in C language?
Ternary operator is a simple expression that can be used instead of if statement. It has the following syntax:
condition? value if true: value if value;
for example:

y=x&gt;10? 2:1;

So y in this example with take either the value of 2 or 1 depending on whether x is greater than 10 or not.

How to open a file in C language?
In C language, we can use the open() function to open a file and get a point to it.

How to read/write data from/to a C file ?
There are many different ways to read/write data from and into a file. For example:
The functions: read(), write(), fscanf(), and fprintf() can be used to read/write data from/to the file.

What are the bitwise shift operators in C language?
Bitwise shift operators shift the bits of a variable. There are many types of them:
>> signed right shift operator.
>>> unsigned right shift operator.
<< left operators.
These operators can be used to manipulate variables by shifting the bit left or right.

How can you return a more than one variable in C language?
The standard way in C language is to return only one value from a function. But as a workaround we can user pointers and structures to return more than one value from the function.

Write a simple function in C language that takes two variables and then exchange their values ?

void exchange(int* var1, int* var2){
    int temp=*var1;

What is the purpose of the switch statement in C language?
Switch statement in C language are used to select one branch to execute in case of the existence of more than one alternatives.

When switch statement is preferred to be used over if-else statement?
If there are just a few branches then if-else statement can be used. Otherwise, switch can be much helpful.

What is the purpose of break and continue keywords?
break and continue are used in combination with loop statements (for, while, etc). The break statement will enforce the loop to exit from that point where break is called. But continue will ask the loop not to continue executing the remaining statements and jump back in a new iteration.

How can you specify command line arguments to your C program?
The main function can be supplied with two other variables: argc and argv and can be written in the form:
int main(int argc, char** argv){

The first variable will count the number of arguments, while the actual arguments will be supplied in argv.

What is the purpose of the default keyword in the C language?
The default keyword can be used in combination with switch statement to handle the default case that is not listed in any of the other cases.

How are nested loops suitable for accessing two dimensional arrays?
Two dimensional arrays consist of rows and columns. Each row can be viewed as another array with a dimension equal to the number of columns. So nested loops can look perfect for this scenario, when the outer loop will work on rows, while inner look handle columns.

How many dimensions we define for arrays in C language?
There is no limit for the number of dimensions that have be used for an array in C language. However, practically, we can use many dimension as much as the system resources permit.

What will be the output of the following C program?

int main(){
  int x=2, y=4;
 printf("%d", x==y? 5:7);
 return 0;

Output : 7

How the standard input and output files are represented in C language?
There are two keywords in the C language to represent standard input and output files: stdin and stdout. The former is used for standard input while the later can be used to refer to the standard output files.

Are arrays in C language passed by value or as a pointer?
When arrays are passed to functions, they are passed as pointers. One reason for this design is that arrays take much space and if they are passed by value, they will need to be copied in memory each time the function is called.

Does C language provide support for concurrency and multi-threading?
No, C does not support concurrency and multi threading. However, there are platform dependent libraries that can support that (e.g., pthreads in Linux and Linux like systems).

Spread the love