C Interview Questions and Answers for Freshers

Explain the keyword continue.

• It is used to take the control to the beginning of the loop.
• It bypasses the statements inside the loop, which have not been executed.
• Continue statement is generally present within a loop and associated with if statement.

Example:
int i, j;
for ( i=1 ; 1<=2 ; i++)
{
   for ( j=1 ; j<=2; j++)
   {
     if (i==j)
       continue ;
    printf (“\n%d %d\n”,i,j);
   }
}

Output of program is 12
21

When the continue statement takes control it bypasses the remaining statements of the inner for loop.

How are decisions made using a switch keyword?

• Switch is combined with case and default keywords to make a control statement.
• Syntax: switch(integer expression)
{
case constant 1:
do this;
case constant 2:
do this;
case constant n:
do this;
default:
do this;
}

• The integer expression yields an integer value.
• This integer value is matched with case constant and if condition for any case is true it executes the statements following the case statement.
• If no case matches then statements following default are executed.

What is the K & R method to declare formal arguments in a function .

• K & R is called as the Kernighan and Ritchie method of declaring arguments.
Example:

calsum(x, y, z)
int x, y, z;
here x,y,z are the formal parameters.

• Here the values x, y, z are defined in the first statement (function declaration).
• Their data types are defined in the second statement.

Give one method for declaration of formal parameters.

• Formal parameters can be declared using ANSI method .
• In this method the data types of the parameters are defined in the function declaration.
• The data types used can be integer, float, char, etc.
• Example: calsum(int x, int y, int z)

Here x,y,z are the formal parameters.

What is garbage value and how it can be avoided?

• If a function is not returning any specific value ,it returns data called garbage value.
Example:

return(a); A
return ; B

• In statement A a specified value ‘a’ is returned.
In statement B no specified value present so it returns a garbage value.
• To avoid the garbage value keyword void is placed before the function name.
Example:

void display ( )
{
printf (“welcome”);
}

Give the difference between call by value and call by reference.

• When a function is called it passes values of variables to called functions.
• This is called as call by value and we have access to formal parameters.
Example:
sum= calsum( a, b, c);

Here calsum is the function and a, b, c are the values passed.

• If instead of the values the addresses of value are passed it is called as call by reference.
• To pass values using call by reference pointers are used and we have access to actual parameters.

Which variables always contain whole numbers?

• Pointers are the variables which always contain data in the form of whole numbers.
• They store the address of other variables.
• They are declared as data type *name of variable.
• It also uses other operator ‘&’ which returns the address of the variable.
Example:
j= &i
Here j is a variable that holds the address of other variable i.

Explain recursion.

• A function is called recursive if a statement within the function can call the same function.
• In circular definition it is the process of defining something in terms of itself.
• It is represented as rec( ).
• An if statement is used within recursive statement to avoid infinite loop.
Example:

rec ( int x)
{
int f;
if (x== 1)
return ( 1 );
else
f=x*rec(x-1);
return ( f );
}
Function to find the factorial of a number.

Can user defined functions be added to the library ?If yes, explain.

• Yes, the user defined functions can be added to the library.
• Also different compilers provide different utilities to modify functions and for c compilers utility called “tlib.exe” (Turbo library) is used.
• Initially create the function and then compile the file using Alt f9.
• This file contains the code in machine language and then add file to the library using the command “ c:\.>tlib math.lib + c:\filename.obj “
• Declare the prototype of function in the header file.
• To include it in a program use syntax : #include “c:\\filename.h”.

Explain the automatic and static storage classes.

• Automatic and static storage classes for variables defined uses memory as the storage.
• These classes are local to the block in which variables are defined.
• Automatic class uses the garbage value as the default initial value.
• Static class uses the default initial value as zero.
• These classes remain till the control remains within block in which the variable is defined.
What are bitwise shift operators?
Bitwise shift operators - The bitwise operators are used for shifting the bits of the first operand left or right. The number of shifts is specified by the second operator...
Explain the use of bit fieild.
Packing of data in a structured format is allowed by using bit fields. When the memory is a premium, bit fields are extremely useful. For example:
Define the scope of static variables.
The scope of a static variable is local to the block in which the variable is defined. However, the value of the static variable persists between two function calls.
Post your comment
Discussion Board
c
try to get something else
kiran 05-27-2015
c
try to get something else
kiran 05-27-2015
c
the difference between the mallaoc and calloc is arguments
i.e.malloc takes single argument
calloc takes a two arguments
raji 01-25-2013
c interview questions for freshers
1. From which of the following libraries below, calloc() belongs to?

stdlib.h
malloc.h
calloc.h
both a and b above


2. What is the main difference between calloc() and malloc()?

calloc() takes a single argument while malloc() needs two arguments
malloc() takes a single argument while calloc() needs two arguments
malloc() initializes the allocated memory to ZERO
calloc() initializes the allocated memory to NULL

3. Which of the following below is/are valid C keywords?

integer
int
null
both a and c above


4. What will be the of the following program?
float x = 3.3;
int i;

i = (int) x;
print i;

3
3.3
3.0
3.00


5. What is the purpose of getc() for?

read a character from STDIN
read a character from a file
both and b above
read a character from an input of user


6. ______________ is used to write formatted output with variable argument lists

vfprintf
vsprintf
vprintf
all of above


7. What is the difference between a structure and a union?

We can define functions within structures but not within a union
We can define functions within union but not within a structure
The way memory is allocated
They have no difference.


8. ___________ will immediately jump to the end of the current block of code

continue
exit
goto
break

9. Importance of "auto" specifier

Automatically initializes a variable to NULL.
Automatically initializes a variable to 0;.
Automatically increments the variable when used.
Indicates that a variable's memory space is allocated upon entry into the block.
Indicates that a variable's memory will automatically be preserved.


10. How to read a character from the keyboard and will store it in the variable a.

a = getchar( stdin );
a = getchar();
a = getc();
getchar( &a )
getc( &a );


11. Which one is used for moving blocks of binary data that are of arbitrary size and position in memory?

strncpy()
memcpy()
memmove()
strcpy()
memset()

12. _________________ function to read a specified number of elements from a file.

gets()
fileread()
readfile()
fread()
getline()


13. What function should be used to release allocated memory which is no longer needed?

free()
dealloc()
release()
dropmem()
unalloc()
c interview questions for freshers 10-14-2012
c interview questions
Here's my profile, would like to contribute to your site.

Ranjeet Singh
Pune

C/C++ SOFTWARE ENGINEER
STORAGE,SYSTEMS
Experience: 4 years +.

Accomplished senior software engineer specializing in object oriented approaches to storage, network and platform development. Extensive background in full life cycle of software development process including requirements gathering, design, coding, testing, debugging and maintenance.

Key strengths include:

-OOPS, Design Patterns
-Data Structures and Algorithms
-Multi-threaded client/server programming using C/C++
-System programming(Not kernel/driver programming!), Inter Process Communication(IPC) and Socket programming using C/C++, SSL/TLS programming using C/C++.
-Unix/Linux and Windows OS Internals
-Software Development Model Followed: AGILE
-Storage Domain, Storage Virtualization and File System Knowledge

TECHNICAL SKILLS

Languages: C, C++, PYTHON
APIs:
STL, PTHREADS, SYSTEM PROGRAMMING(Not kernel/driver programming!)
Methodologies: OOPS, UML, DESIGN PATTERNS
Operating Systems: UNIX, LINUX, SOLARIS, VmWare, WINDOWS
Network Protocols Knowledge: TCP/IP, UDP, SOAP, SSL/TLS, SNMP, HTTP
Storage Protocols Knowledge: FC, SCSI, iSCSI, SAS
Tools: (VC++), GCC, GDB, CLEARCASE, GSOAP,TCPDUMP/TCPTRACE
RDBMS: MSSQL Server, SQL

Awards/Recognitions received at EMC:

-Received BRONZE AWARD at EMC for performance and innovative excellence.
-Received SELECT AWARD at EMC for performance and innovative excellence.
Ranjeet 10-14-2012
C interview questions
C interview questions and answers are very useful. I am quite impress and would like to add more questions on it. Here's my brief candidature:

Kunal Kapoor
Location - Pune

An accomplished Software Engineer specializing in object-oriented Design and Analysis with extensive experience in the full life cycle of the software design process including requirement definition, prototyping , design, development and implementation.

Technical Expertise

Languages - C, C++, VC++, MFC, Data Structures.
Skill Set - Visual Studio 6.0/ 2005/2008/2010, MFC, Win32, SDK, Design Patterns, COM, STL, Multithreading, BCGSoft Controls, DLLs, Codejock.
Verix Terminals - Vx 510, Vx 520, Verix Operating System, MagIC terminals
Database - SQL Server 2000/2005/2008
Operating Systems - Windows-XP/Vista/7/Server-2003/ 2000/98 NT, Linux
Responsibilities - Coding, Development, designing.

Professional Experience

1. Deelite Sales Pvt Ltd [ Jan 2012 – July 2012]

Profile: Senior Software Design Engineer (Software Analyst, C, C++, Visual Studio 2005). Responsible for developing software applications for Verifone terminals like Vx 510, Vx 520 etc.

2. Nite software Pvt. Ltd. [ Dec 2006 – Jan 2012]

Profile: Software Engineer (VC++, MFC, Visual Studio 6.0, Visual Studio 2008,Visual Studio 2005, SQL Server 2000/2005/2008, STL,Multithreading). Responsible for developing software applications on windows platform.

Total Experience: 5 years and 7 months as Software Engineer.

Projects:

1. Migration from Exchange to Lotus Notes
Software tool migrates the user mailboxes from Microsoft Exchange environment to Lotus Notes environment. Software performs conversion of single Exchange mailbox and Exchange users mailboxes and then saves the entire converted items of Exchange mailboxes in user defined saving option i.e. NSF.

Role: Software Engineer responsible for coding and development [Team Size: 3,
Company: Lepide Software Pvt. Ltd].
Skills: Visual Studio 6.0/2008, VC++, MFC, Redemption.dll, profman.dll, Lotus Notes API,
MAPI, SDK, Multithreading, Win32, DLL, BCGSoft controls.

2. Backup Utility
The Chily Backup utility helps you create a copy of the information on your hard disk. In the event that the original data on your hard disk is accidentally erased or overwritten, or becomes inaccessible because of a hard disk malfunction, you can use the copy to restore your lost or damaged data. The Chily Backup utility helps you protect data from accidental loss. For example, you can use Chily Backup to create a duplicate copy of the data on your hard disk and then archive the data on another storage device.

Role: Software Engineer responsible for coding and development [Team Size: 3, Time:
11 months, Company: Lepide Software Pvt. Ltd].
Skills: Visual Studio 6.0, VC++, MFC, SDK, Multithreading, Win32, DLL.

3. Migration from Groupwise to Lotus Notes

GoupWise to Lotus Notes Migration: software tool migrates the user mailboxes from Novell GroupWise environment to Lotus Notes environment. Software performs conversion of single GroupWise mailbox and batch of GroupWise mailboxes and then saves the entire converted items of GroupWise mailboxes in user defined saving option i.e. NSF.

Role: Software Engineer responsible for coding and development [Team Size: 3].
Skills: Visual Studio 6.0, VC++, MFC, Lotus Notes API, Groupwise API, Codejock, SDK,
Multithreading, Win32.


Education Qualification

Degree: B-Tech (Electronics & Communication).
School: Bal Bharti Public School.
kunal 10-14-2012

You may like