C Interview Questions and Answers

The 'C' programming language was originally developed for and implemented on the UNIX operating system, on a DEC PDP-11 by Dennis Ritchie. One of the best features of C is that it is not tied to any particular hardware or system. This makes it easy for a user to write programs that will run without any changes on practically all machines. C is often called a middle-level computer language as it combines the elements of high-level languages with the functionalism of assembly language. C allows the manipulation of bits, bytes and addresses- the basic elements with which the computer functions. Another good point about C is its portability which makes it possible to adapt software written for one type of computer to another. C was created, influenced, and field tested by working programmers. The end result is that C gives the programmer what the programmer wants. C offers the speed of assembly language and the extensibility of FORTH, but few of the restrictions of Pascal and Modula-2.

C Language Interviews are getting tough these days as the technology grows faster. To get through the C Language interview one needs to update him/herself in a regular manner. Having said that, just before the interview, it is very important to have a quick glance of the reputed C Language questions and answers to make yourself comfortable during the interview process. This is where DoAnswers.com helps you in renewing yourself on C Language and various other technologies interview preparation.



Next >>

 

1. How can I access memory located at a certain address

Ans : Use a pointer to that address. 12 How can I read a directory in a C program? Like the following code illustrates: #include ?stdio.h? #include ?dirent.h? #include ?errno.h? int main() { DIR *pdir; struct dirent *pfile; if (!(pdir = opendir( ?MyDirectoryPath? ) ) ) { perror(?Can?t open this directory.?); return 1; } while( (pfile = readdir(pdir)) ) { if ( 0 == strcmp(pfile->d_name,?.?) ) continue; else if( 0 == strcmp(pfile->d_name,?..?) ) continue; else printf(?File : %s\n?, pfile->d_name ); } return 0; }


2. How can I call a function, given its name as a string?

Simple way (students) void foo( void ); void zoo( void ); void caller( const char * fname ) { if( strcmp(fname,?foo?) == 0 ) foo(); else if ( strcmp(fname,?zoo?) == 0 ) zoo(); else default; } Better Way: Use an XML schema that describes keywords associated with functions implemented as dynamic libraries. Use expat library to parse the elements and call functions. Correct Way: Use a lexer and compiler builder (lex,yacc) to create a set of tokens and handler functions. Good but time expensive way. Compile the function as a dll and call it during run time using


3. How can I convert integers to binary or hexadecimal?

In order to print them use appropriate format in printf. In order to assign them use specifiers like int x = FFx; x = 101110b; Integers are kept in the same format inside program?s heap/stack.


4. How can I increase the allowable number of simultaneously open files?

This is system depended. In some you cannot.


5. How can I invoke another program from within a C program?

Use in UNIX use the exec, execl, execv, execle, execve, execlp, execvp functions.


Your Ad Here

6. How can I return multiple values from a function?

return structure from function which can hold multiple variable


7. How do I access command-line arguments?

Ans : Declare your main() like: int main(int argc, char * argv[]) { } argc is the number of arguments stated in the command line. Use argv[0] to get the program (process) name Use argv[1],?, to argv[argc-1] to get the command lines


8. How do I know how many elements an array can hold?

The amount of memory an array can consume depends on the data type of an array. In DOS environment, the amount of memory an array can consume depends on the current memory model (i.e. Tiny, Small, Large, Huge, etc.). In general an array cannot consume more than 64 kb. Consider following program, which shows the maximum number of elements an array of type int, float and char can have in case of Small memory model. main( ) { int i[32767] ; float f[16383] ; char s[65535] ; }


9. How do you write a program which produces its own source code as its output?

#include #include using namespace std; int main() { char buf[100]; string str; int size=100; ifstream in(?filename.cpp?,ios::in); while(!in.eof()) { while(in.getline(buf,size)) { str=buf; cout


10. Program to counte the number of bits set to 1

int bits_set( int word ) { int tmp; tmp = (word >> 1) & 033333333333; tmp = word - tmp - ((tmp >> 1) & 033333333333); return (((tmp + (tmp >> 3)) & 030707070707) % 077); }


Your Ad Here

Next >>

 
Databases Questions and Answers
 
DB2 Interview Questions and Answers
IMS Interview Questions and Answers
MYSQL Interview Questions and Answers
Oracle Interview Questions and Answers
PL/SQL Interview Questions And Answers
Quel Interview Questions and Answers
SQL Interview Questions and Answers

 
 
.NET Interview Questions and Answers
 
ASP Interview Questions and Answers
C# Interview Questions and Answers
Visual Basic Interview Questions and Answers
 
J2EE Interview Questions and Answers
 
Enterprise Java Beans (EJB) Interview Questions And Answers
Hibernate Interview Questions And Answers
Jave Messaging Service (JMS) Interview Questions And Answers
Jave Server Faces (JSF) Interview Questions And Answers
Java Server Pages (JSP) Interview Questions And Answers
Servlets Interview Questions And Answers
Spring Framework Interview Questions And Answers
Struts Framework Interview Questions And Answers
 
JAVA Interview Questions and Answers
 
Core Java Interview Questions and Answers
Java Platform, Micro Edition (Java ME) Interview Questions And Answers
JAVA GUI Interview Questions and Answers
Java Performance Tuning Interview Questions And Answers
JUnit Interview Questions And Answers
Remote Method Invocation (RMI) Interview Questions And Answers
Unified Modeling Language (UML) Interview Questions And Answers
 
Java Application Server Interview Questions And Answers
 
Tomcat Application Server Interview Questions And Answers
WebLogic Application Server Interview Questions And Answers
 
Mainframe Interview Questions and Answers
 
CICS Interview Questions and Answers
COBOL Interview Questions and Answers
IMS Interview Questions and Answers
JCL Interview Questions and Answers
REXX Interview Questions and Answers
TELON Interview Questions and Answers
VSAM Interview Questions and Answers
 
Object Oriented Language Questions and Answers
 
C Interview Questions and Answers
C++ Interview Questions and Answers
Eiffel Interview Questions and Answers
J2EE Interview Questions and Answers
JAVA Interview Questions and Answers
Sather Interview Questions and Answers
Small talk Interview Questions and Answers
 
Operation Systems Interview Questions and Answers
 
MS DOS Interview Questions and Answers
Unix OS Interview Questions and Answers
Windows Interview Questions and Answers
 
Scripting languages Interview Questions and Answers
 
Java Script Interview Questions and Answers
Practical Extraction and Reporting Language Interview Questions and Answers
PHP Interview Questions and Answers
VBScript Interview Questions and Answers
 
UserInterfaces Questions and Answers
 
Foxit Interview Questions and Answers
Glade Interview Questions and Answers
Tweak Interview Questions and Answers
 
WEB Technologies Questions and Answers
 
AJAX Interview Questions and Answers
HTML Interview Questions and Answers
WML Interview Questions and Answers
XML Interview Questions and Answers
 
Interview Tips And Some Common Questions
 
Behavioral Interview Questions And Answers


Your Ad Here