C Interview Question and Answers

by Admin on February 25, 2012

1.    Define a structure?

A.    A structure is a set of variables positioned under one name, offering a suitable means of relevant information together. Declaration of structure creates a template which can be used to produce structure objects that are called as its instances. The variables which form the structure are called as members, also referred as fields or elements.

2.    Define a pointer?

A.    A pointer is nothing but a reference to some memory location. As a computer has billions or may be even trillions of cells, every cell can be filled with some data. With the help of pointers, one can know and access the value of its memory cell and its location.

3.    What are the advantages of a pointer?

A.    Dynamic Memory Allocation, Passing structures and array to functions, creating data structures like linked lists, trees and so on, and passing addresses to functions.

4.    Define static variable?

A.    A special variable which is stored in the data segment not like the default auto variable that is stored in stack, is called static variable. It can be initialized through using keyword static before variable name.

5.    How are structure passing and returning implemented?

A.    When you pass structures as arguments to functions, the whole structure is usually pushed on the stack, through as several words as are needed. To avoid this overhead, programmers usually opt to use pointers to structures instead. Some compilers simply pass a pointer to the structure, even though they have to produce a local copy to save pass-by-value semantics.

Structures are usually returned from functions in a position pointed to by an additional, compiler-supplied hidden argument to the function. Few older compilers used to use unique, static locations for structure returns, though this made structure-valued functions non-reentrant that ANSI C disapproves.

6.    Why can’t we compare structures?

A.    We do not have one or fine way for a compiler to apply structure evaluation that is constant with lower level flavor of C. A plain byte-by-bye comparison could be found on random bits available in unused ‘holes’ in the structure; such filling is used to maintain the arrangement of following fields accurate. A field-by-field assessment may require improper amounts of recurring code for larger structures.

7.    Why doesn’t struct x { … };x thestruct; work?

A.    C is not similar to C++. Typedef names are not automatically produced for structure tags

8.    Why doesn’t this code: a[i] = i++; work?

A.    The subexpression i++ creates a side effect. It changes i’s value which directs to undefined behavior as i as well is referenced somewhere else in the same expression

9.    Can we initialize unions?

A.    ANSI C permits an initializer for the foremost member of a union. We do not have any standard method of initializing other members (there is no way even under a pre-ANSI compiler to initialize a unionl)

10.    Can main () be called recursively?

A.    Yes, any function that has main() could be called recurrently.

11.    Are the variables argc and argv are always local to main?

A.    Yes, argc and argv are local to main

12.    What would be the similar pointer expression for referring the equivalent element as a[p][q][r][s]?

A.    *( * ( * ( * (a+p) + q ) + r ) + s)

13.    Are the expressions *ptr ++ and ++ *ptr same?

A.    No. *ptr++ increments pointer, not the value pointed by it. Where as ++*ptr increments the value being pointed to by ptr.

14.    What are the benefits of using array of pointers to string instead of an array of strings?

A.    (i) Effective usage of memory
(ii) Simpler to swap the strings through moving their pointers when sorting

15.    Discuss on pointer arithmetic?

A.   (i)  Assigning pointers to the similar kind of pointers

(ii)  Subtracting or adding a pointer and an integer

(iii) comparing and subtracting two pointers

(iv) Decrementing or incrementing the pointer that are pointing to the     elements of an array while a pointer to an integer is added by one, the address is added by two. The Compiler does this automatically.
Assiging value 0 to the pointer variable and comparing it with the pointer. Pointer consisting 0 points to nothing at all

16.    What is the invalid pointer arithmetic?

A.    (i) Adding, dividing and multiplying two pointers
(ii) Adding double or float to pointer
(iii) Masking or shifting pointer
(iv) Assigning a pointer of one type to another type of pointer.

17.    Is the allocated space within a function automatically deallocated when the function returns?

A.    None of the pointers are similar to that of what they actually point to. Local variables like local pointer variables in a function are automatically deallocated if function returns. However, coming to a local pointer variable, deallocation is nothing but the pointer being deallocated and not blocking of memory allocated to it. Memory that is allocated dynamically always continues till the program terminates or allocation is freed.

18.    What are the pointer declarations used in C?

A.    (i) Pointers to an array
(ii) Array of pointers
(iii) Pointer to a data type
(iv) Pointer to a pointer
(v) Function returning a pointer

19.    Can we use any name in place of argv and argc as command line arguments?

A.    Yes. We can certainly use any user defined name instead of argc and argv.

20.    Difference between an array of pointers and a pointer to an array?

A.    Array of pointers
(i) Declaration – data type *array_name[size]
(ii) Size indicates size of the row
(iii) The space for columns may be dynamically allocated
Pointer of Arrays
(i) Declaration – data_type (*array_name)[size]
(ii) Size indicates size of the column

21.    Difference between an array name and a pointer variable?

A.    A pointer variable is a variable while an array name is not a variable but is a fixed address. Unlike a pointer variable, array name cannot be initialized. An array name being a constant value, — and ++ operators can not be applied to it.

22.    What is the purpose of rewind()?

A.    The rewind() function is used to get the file pointer to the starting of the file. Rewind (fp);
Fp is a file pointer.
And we can get similar effect through
feek(fp,0,0);

23.    What is the purpose of ftell?

A.    The ftell() function is used to get the current file referred by the file pointer. ftell(fp); returns a long integer value referring the current location of the file pointed by the file pointer fp. If any error occurs, it will return -1.

24.    What is a random access file?

A.    A file can be accessed at random through function fseek(),
fseek(fp,position,origin); file pointer number file pointer fp positions number of bytes offset origin from 0, 1 or 2 denoting the starting, current or end position of the file respectively.

25.    How is fopen()used?

A.    The fopen() function return a file pointer. So a file pointer is declared and is assigned as
FILE *fp;
fp=fopen(filename,mode);

26.    How is a file closed?

A.    A file is closed using fclose() function

27.    What is a file pointer?

A.    The pointer to a FILE data type is known as a file pointer or a stream pointer. This pointer points to the block of information of the stream/file that had just been accessed.

28.    What is a stream?

A.    A stream is nothing but source of destination of data or simply data that is associated with a hard disk or other input/output device. The source stream that offers data to a program is known as input stream and the source stream that receives the result from the program is known as output stream.

29.    What is meant by file opening?
A.    The process of connecting a program to a file is known as file opening. It needs I/O stream creation in advance to writing or reading the data.

30.    What exactly is a file?
A.    A file is an area of storage in auxiliary storage devices or in hard disks. It includes information in bytes.

31.    What are the types of files?

A.  Files are of two types
1-high level files (stream oriented files) – These  are accessed through library functions
2-low level files (system oriented files) – These are accessed through system calls

32.    What is the difference between the functions memmove() and memcpy()?

A.    The arguments of memmove() can overlie in memory, while the arguments of memcpy() cannot

33.    What do the functions atoi(), itoa() and gcvt() do?

A.    atoi() is a macro that converts integer to character.
itoa() It converts an integer to string
gcvt() It converts a floating point number to string

34.    How would you use the functions randomize() and random()?

A.    Randomize() initiates random number generation with a random value.
Random() generates random number between 0 and n-1

35.    What are the two forms of #include directive?

A.
1. #include“filename”
2. #include

36.    What are the facilities provided by preprocessor?

A.    File inclusion, substitution facility and conditional compilation

37.    What is a preprocessor? What are the advantages of preprocessor?

A.    Preprocessor practices the source code program before it is sent through the compiler.
(i) It includes the readability of a program
(ii) It helps in easier modification
(iii) It facilitates writing convenient programs
(iv) It helps in easier debugging
(v) It helps in testing a portion of program
(vi) It enables implementing comprehensive program

38.    Define bit fields? Point out their uses in Structure declaration?

A.    A bit field is a group of adjoining bits in a one execution based on storage unit which we call as a “word”.
Usually, the field definition’s syntax and access is based on a structure.
Struct {
unsigned int k :1;
unsigned int l :1;
unsigned int m :1;
}flags;

The number that is preceeding the colon indicates the field width. And flag is a variable that includes 3 bit fields.

39.    What is the maximum combined length of command line arguments including the space between adjacent arguments?

A.    It depends on the operating system

40.    Compose a program to swap two variables without the help of third variable.

A.    a^=b;
b^=a;
a^=b;
In the above program, the numbers are converted into binary numbers and then xor operator is executed.

41.    What is pre-increment and post-increment?

A.    ++num (pre-increment) increases value of num before it is used in the expression, where num++ (post-increment) increases the num after its value is used.

42.    Difference between logical vs syntax errors?

A.    Logical error:
It occurs by a wrong algorithm or a mistyped statement in such a way that it does not violate the syntax, and these are difficult to find.

Syntax error:

It involves syntax validation, and compiler prints diagnostic message.
Ex: a=b

43.    What are C identifiers?

A.    C identifiers are the names given to different programming elements like arrays, functions and variables. It is usually a combination of a letter, a digit and an underscore. It should start with a letter, and backspace is not allowed.

44.    What are C tokens?

A.    There are 6 classes of C tokens – keywords, constants, identifier, operators, string literals and other separators.

45.    What do the ‘c’ and ‘v’ in argc and argv stand for?

A.    The c in argument count, argc stands for the number of the command line argument that the program is invoked with. And v in argument vector, argv is a pointer to an array of the character string that contains the argument.

46.    Difference between array and pointer?

A.    Array:
(i) Arrays allocate space, automatically
(ii) They can not be reassigned
(iii) They can not be resized
(iv) sizeof (arrayname) returns the number of bytes occupied by the array.

Pointer:

(i) Assigned explicitly to point an allocated space.
(ii) It can be reassigned
(iii) It can be resized using realloc() function
(iv) sizeof (p) gives the number of bytes used to store the pointer variable p.

47.    Compose a program using Command Line Arguments?

A.
#include
void main(int argc,char *argv[])
{
int i;
clrscr();
for(i=0;i
printf(“\n%d”,argv[i]);
}

48.    Write a program which employs Recursion?

A.    int fact(int n) { return n > 1 ? n * fact(n – 1) : 1; }

49.    How can we read/write Structures from/to data files?

A.    To compose a structure fwrite() can be used as Fwrite(&e, sizeof(e),1,fp); Here, e is a structure variable. A consequent fread() invocation will be able to read the structure back from file. Calling function fwrite() will write out sizeof(e) byte from the address & e. Data files that are written as memory images with function fwrite(), but will not be portable, especially if they include floating point fields or pointers. It is because structures’ memory layout is compiler and machine dependent. Hence, structures written as memory are not need to be read back by programs running on other machine, also this is an important factor if the data files that you are writing will ever be exchanged between machines.

50.    Can a Structure contain a Pointer to itself?

A.    Yes such structures are called self-referential structures.

Other Questions

  1. What is the similarity between a Structure, Union and enumeration?
  2. How are Structure passing and returning implemented by the complier?
  3. What is the difference between an enumeration and a set of pre-processor # defines?
  4. Is it possible to have more than one main() function in a C program?
  5. Difference between formal argument and actual argument?
  6. What are built in functions?
  7. What is an argument?
  8. What is a function?
  9. What modular programming?
  10. Why is it necessary to give the size of an array in an array declaration?
  11. Is it possible to have negative index in an array?
  12. Difference between linker and linkage?
  13. What is an array of pointers?
  14. What is pointer to a pointer?
  15. What is the purpose of realloc?
  16. What is dynamic memory allocation?
  17. What is static memory allocation?
  18. How pointer variables are initialized?
  19. Are the expressions arr and &arr same for an array of integers?
  20. What is generic pointer in C?
  21. What does the error ‘Null Pointer Assignment’ means and what causes this error?
  22. Are pointers integer?
  23. What is a NULL Pointer? Whether it is same as an uninitialized pointer?
  24. In C, why is the void pointer useful? When would you use it?
  25. What is near pointer?
  26. What is a normalized pointer, how do we normalize a pointer?
  27. What is a huge pointer?
  28. What is a far pointer? Where do we use it?
  29. What is the difference between Strings and Arrays?
  30. What the advantages of using Unions?
  31. What is storage class? What are the different storage classes in C?
  32. Differentiate between a for loop and a while loop? What are it uses?
  33. What is recursion?
  34. Difference between strdup and strcpy?
  35. Out of fgets() and gets() which function is safe to use and why?
  36. Can we specify variable field width in a scanf()
  37. What is the use of typedef?
  38. What are register variables? What are the advantages
  39. Describe about storage allocation and scope of
  40. What are enumerations?
  41. Difference between arrays and linked list?
  42. Where does global, static, and local, register
  43. Where is the auto variables stored?
  44. What is static identifier?
  45. Difference between pass by reference and pass by value?
  46. What are macros? What are its advantages and disadvantages?
  47. What are the differences between malloc () and calloc ()?
  48. In header files whether functions are declared or defined?
  49. What are the differences between structures and arrays?
  50. What are the differences between structures and unions?

{ 0 comments }

Career Guidance

by Admin on February 24, 2012

For any student who is just about to pass out from college, the future seems to be a big mystery because college life has been full of fun and being carefree with all their needs being taken care of by their parents and elders.

Suddenly, they find themselves being forced to take a decision on which way they would like to go in the future and with no sufficient information, they find it very difficult to make a good choice and need to be guided.

Most students seek to find employment in some good company or the other and very few if any, will look to setup their own businesses simply because of lack of authentic information of the requirements and procedures.

Career guidance sessions are usually the best way for such students to aid them in making the right choice of a career. These courses are usually conducted by people who keep themselves abreast of all the latest developments and openings in the business and corporate world.

Nowadays, there is a lot of information to be got from the Internet. However one should be cautious not to take everything they read there at face value but do some research of their own to verify and authenticate this information before concluding on their choice of a career.

While searching for information, focus all your attention on yourself, your interests, your likes and dislikes and any dreams or goals you may want to achieve since this is all about you and your future life.

Have a plan

Despite a certain level of uncertainty which is to be expected at this stage, try and come up with a plan. You can refine this as you go along but there should be some kind of focus to begin with. So, in order to set up your plan, find out what your interests are and what you like to do. List them down if there are many of them.

Also note down what you can do well and what you enjoy doing because this way, you will not feel like you are working at all.

Your personality is very important too and knowing what kind of a person you are can help you understand if a particular career is meant for you or not. It is equally important to note down what is really important for you and what values you possess. Accordingly, you will understand where you fit in.

Explore and experience

Study and learn as much as you can about the jobs you would like to do because neither at school nor at college will you be able to attend a lecture that will teach you a career as it is in real life. You need to be enterprising enough to explore and experience what it is like to work in a particular job.

It is a good idea to take up an internship or even part time employment while you are still studying. The more of this you can do while studying, the better prepared you will be when you are really ready to take up your first occupation.

Set up your priorities

Prioritizing is the art of listing your preferences beginning with the strongest one at the top and following it through to the bottom. After getting involved in both the procedures listed above, you will have got a very good idea of what you would prefer to do and what not. Some may not prefer to work in an office while some others may be aware that their love of painting or sketching will not help them to sustain their careers and so these are the kinds of things you need to take care of when prioritizing.

If you follow these procedures, you will learn and discover more about yourself and this is a definite advantage to you when you finally decide on the career you want to follow. This is a key part of planning for your career.

No decision is final

Remember that no matter what decisions you make at this point, none of it is going to be binding on you forever and you may find that you may have a change of heart very soon after you have apparently ‘finally’ decided. This is a very natural thing to do as many people do change their careers many times and your first job will not necessarily be the career you have dreamt of, say ten or more years down the line.

So there is no need to be rigid with yourself and force yourself to take a perfect decision the first time, but use whatever resources you can lay your hands on and most of all keep a watchful eye out for every opportunity that may come your way to enhance your career.

Where to find help?

Most students are at a loss where to find help in choosing a career and there is no one perfect source from where you will get the necessary information. Career guidance is to be found everywhere, all you have to do is just ask anyone and you will get some information or the other. For instance, your teachers and professors while you are studying can certainly give you information like the academic qualifications you need for various career choices that you may make.

Other students and friends will also share what they have come to know from their own sources and even your own parents can probably be better guides than most since they also know your strengths and weaknesses which others may not be aware of.

The best source could be from the professionals who work in the same field or fields that you are keen on making a career out of. Then there are the career counselors in your own college or the professional counseling centers who can also guide you very comprehensively after assessing your skills, strengths and weaknesses by administering several aptitude tests and evaluating them.

{ 0 comments }

Interview Tips

February 23, 2012

Facing an interview is a vital procedure of finding a perfect job that will boost up your career. Most of the interview tips are honestly based on your common sense. However, often many candidates ignore few things that they should be ready for while attending the interview, sometimes it may be because of the tension. [...]

Read the full article →

Personality Test

February 22, 2012

What is it? It is a form of testing that reveals or is able to interpret the kind of person you are, how you behave and predict how you would react to a given situation based on your present and past behavior and choices. A Personality Test can be conducted as a questionnaire or use [...]

Read the full article →

How To Improve Concentration?

February 22, 2012

In this competitive world everybody is aware of the importance and power of Concentration. Following are few tips to assist you improve your concentration ability irrespective of your task whether you are working, studying or doing something else. 1. A simple exercise There is one easy exercise that can help you develop your concentration level. [...]

Read the full article →

How To Improve English?

February 22, 2012

Without a doubt, Today English is the most popularly and widely spoken language in the world. Nearly every country in the world has some proportion of English speaking population living there, studying and even doing businesses for quite some time now. Considering this, the importance of knowing this language can not be emphasized enough and [...]

Read the full article →

How To Improve Communication Skills?

February 22, 2012

If you have to succeed in the contemporary world of career opportunities, or even home-based business, excellent communication skills are an absolute asset and anyone who is entering the corporate world be it a small start-up company or a large corporation, having good and well developed communication skills are a must to progress up the [...]

Read the full article →

Interview Questions And Answers

February 21, 2012

Following are some typically encountered interview questions. Review the questions and just practice how you could answer them; you can find few suggestions as well: 1. Tell me about yourself This is the most commonly asked questions during an interview. You have to keep a short statement already prepared in your mind. Be careful in [...]

Read the full article →

Science Projects – School Level

February 10, 2012

A Science Project is an academic activity of students participating in construction or experiments of models in any of the disciplines from science. Students are assigned to do such projects either to present them in front of their teachers and classmates or sometimes asked to present the projects in a science fair. Involving in science [...]

Read the full article →

Physics Projects

February 3, 2012

Physics is a branch of natural science that studies about matter and its movements through space time, with its related theories like force and energy. More elaborately, it is the common study of nature, performed to know how the Universe acts. It is one of the oldest branches of natural science, in fact the oldest [...]

Read the full article →