0% found this document useful (0 votes)
20 views9 pages

C Programming short QNA

Uploaded by

sadabjaowad69
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
0% found this document useful (0 votes)
20 views9 pages

C Programming short QNA

Uploaded by

sadabjaowad69
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 9

C Programming QNA

1. What is a pointer on pointer?

It’s a pointer variable which can hold the address of another pointer variable. It de-
refers twice to point to the data held by the designated pointer variable.

Eg: int x = 5, *p=&x, **q=&p;

Therefore ‘x’ can be accessed by **q.

2. Distinguish between malloc() & calloc() memory allocation.

Both allocates memory from heap area/dynamic memory. By default calloc fills the
allocated memory with 0’s.

3. What is keyword auto for?

By default every local variable of the function is automatic (auto). In the below
function both the variables ‘i’ and ‘j’ are automatic variables.

void f() {

int i;

auto int j;

NOTE − A global variable can’t be an automatic variable.

4. What are the valid places for the keyword break to appear?

Break can appear only with in the looping control and switch statement. The purpose
of the break is to bring the control out from the said blocks.
5. What is difference between including the header file with-in angular braces <
> and double quotes “ “

If a header file is included with in < > then the compiler searches for the particular
header file only with in the built in include path. If a header file is included with in “ “,
then the compiler searches for the particular header file first in the current working
directory, if not found then in the built in include path.

6. How a negative integer is stored?

Get the two’s compliment of the same positive integer. Eg: 1011 (-5)

Step-1 − One’s compliment of 5 : 1010

Step-2 − Add 1 to above, giving 1011, which is -5

7. What is a static variable?

A static local variables retains its value between the function call and the default value
is 0. The following function will print 1 2 3 if called thrice.

void f() {

static int i;

++i;

printf(“%d “,i);

If a global variable is static then its visibility is limited to the same source code.
8. What is a NULL pointer?

A pointer pointing to nothing is called so. Eg: char *p=NULL;

9. S++ or S = S+1, which can be recommended to increment the value by 1 and


why?

S++, as it is single machine instruction (INC) internally.

10. What is a dangling pointer?

A pointer initially holding valid address, but later the held address is released or freed.
Then such a pointer is called as dangling pointer.
11. What is the purpose of the keyword typedef?

It is used to alias the existing type. Also used to simplify the complex declaration of
the type.

12. What is lvalue and rvalue?

The expression appearing on right side of the assignment operator is called as rvalue.
Rvalue is assigned to lvalue, which appears on left side of the assignment operator. The
lvalue should designate to a variable not a constant.

13. What is the difference between actual and formal parameters?

The parameters sent to the function at calling end are called as actual parameters while
at the receiving of the function definition called as formal parameters.

14. Can a program be compiled without main() function?

Yes, it can be but cannot be executed, as the execution requires main() function
definition.

15. What is the advantage of declaring void pointers?

When we do not know what type of the memory address the pointer variable is going
to hold, then we declare a void pointer for such.

16. What is a nested structure?

A structure containing an element of another structure as its member is referred so.

17. What is the difference between variable declaration and variable definition?

Declaration associates type to the variable whereas definition gives the value to the
variable.
18. Does a built-in header file contains built-in function definition?

No, the header file only declares function. The definition is in library which is linked
by the linker.

19. What is a token?

Token is every individual unit of a program. A C program consists of various tokens


and a token is either a keyword, an identifier, a constant, a string literal, or a symbol.
20. How many tokens are there in c?

There are 6 tokens:


1. Keywords.
2. Identifiers.
3. Constants.
4. Special symbols.
5. Strings.
6. Operators.

21. What is a preprocessor?

Preprocessor is a directive to the compiler to perform certain things before the actual
compilation process begins.

22. When to use -> (arrow) operator?

If the structure/union variable is a pointer variable, to access structure/union elements


the arrow operator is used.

23. What are command line arguments?

The arguments which we pass to the main() function while executing the program are
called as command line arguments.

24. What is the output file generated by the linker.

Linker generates the executable file.


25. What are the different ways of passing parameters to the functions? Which to
use when?

• Call by value − We send only values to the function as parameters. We


choose this if we do not want the actual parameters to be modified with
formal parameters but just used.

• Call by reference − We send address of the actual parameters instead of


values. We choose this if we do want the actual parameters to be modified
with formal parameters.

26. Describe the file opening mode “w+”.

Opens a file both for reading and writing. If a file is not existing it creates one, else if
the file is existing it will be over written.

27. Where the address of operator (&) cannot be used?

It cannot be used on constants.

28. Is FILE a built-in data type?

No, it is a structure defined in stdio.h.

29. What is reminder for 5.0 % 2?

Error, It is invalid that either of the operands for the modulus operator (%) is a real
number.

30. How many operators are there under the category of ternary operators?

There is only one operator and is conditional operator (? : )


31. Define an array.

Array is collection of similar data items under a common name.

32. Who designed C programming language?

Dennis M Ritchie.

33. What is an infinite loop?

A loop executing repeatedly as the loop-expression always evaluates to true such


as

while(0 == 0) {

34. What is the default value of local and global variables?

Local variables get garbage value and global variables get a value 0 by default.

35. Can a pointer access the array?

Pointer by holding array’s base address can access the array.

36. What is typecasting?

Typecasting is a way to convert a variable/constant from one type to another type.

37. What is recursion?

Function calling itself is called as recursion.

38. How can we determine whether a file is successfully opened or not using
fopen() function?

On failure fopen() returns NULL, otherwise opened successfully.


39. Is that possible to store 32768 in an int data type variable?

int data type only capable of storing values between – 32768 to 32767.To store 32768
a modifier needs to use with int data type. Long Int can use and also if there is no any
negative values unsigned int is also possible to use.

40. What are the modifiers available in C programming language?

There are 5 modifiers available in C programming language as follows.

• Short
• Long
• Signed
• Unsigned
• long long

41. What is a nested loop?

A loop running within another loop is referred as a nested loop. The first loop is called
Outer loop and inside the loop is called Inner loop. Inner loop executes the number of
times define an outer loop.

42. What is the difference between ++a and a++?

++a is called prefixed increment and the increment will happen first on a variable. a++ is
called postfix increment and the increment happens after the value of a variable used for
the operations.

43. What is the difference between Call by Value and Call by Reference?

When using Call by Value, you are sending the value of a variable as parameter to a
function, whereas Call by Reference sends the address of the variable. Also, under Call
by Value, the value in the parameter is not affected by whatever operation that takes
place, while in the case of Call by Reference, values can be affected by the process
within the function.

44. Differentiate Source Codes from Object Codes

Source codes are codes that were written by the programmer. It is made up of the
commands and other English-like keywords that are supposed to instruct the computer
what to do. However, computers would not be able to understand source codes.
Therefore, source codes are compiled using a compiler. The resulting outputs are object
codes.
45. Compare and contrast compilers from interpreters.

Compilers and interpreters often deal with how program codes are executed.
Interpreters execute program codes one line at a time, while compilers take the program
as a whole and convert it into object code, before executing it. The key difference here
is that in the case of interpreters, a program may encounter syntax errors in the middle
of execution, and will stop from there. On the other hand, compilers check the syntax
of the entire program and will only proceed to execution when no syntax errors are
found.

46. What are header files and what are its uses in C programming?

Header files are also known as library files. They contain two essential things: the
definitions and prototypes of functions being used in a program. Simply put, commands
that you use in C programming are actually functions that are defined from within each
header files. Each header file contains a set of functions. For example: stdio.h is a
header file that contains definition and prototypes of commands like printf and scanf.

47. What is syntax error?

Syntax errors are associated with mistakes in the use of a programming language. It
maybe a command that was misspelled or a command that must was entered in
lowercase mode but was instead entered with an upper case character. A misplaced
symbol, or lack of symbol, somewhere within a line of code can also lead to syntax
error.

48. What are variables and it what way is it different from constants?

Variables and constants may at first look similar in a sense that both are identifiers
made up of one character or more characters (letters, numbers and a few allowable
symbols). Both will also hold a particular value. Values held by a variable can be
altered throughout the program, and can be used in most operations and computations.
Constants are given values at one time only, placed at the beginning of a program. This
value is not altered in the program. For example, you can assigned a constant named PI
and give it a value 3.1415 . You can then use it as PI in the program, instead of having
to write 3.1415 each time you need it.

49. What is debugging?

Debugging is the process of identifying errors within a program. During program


compilation, errors that are found will stop the program from executing completely. At
this state, the programmer would look into the possible portions where the error
occurred. Debugging ensures the removal of errors, and plays an important role in
ensuring that the expected program output is met.
50. What are preprocessor directives?

Preprocessor directives are placed at the beginning of every C program. This is where
library files are specified, which would depend on what functions are to be used in the
program. Another use of preprocessor directives is the declaration of constants.
Preprocessor directives begin with the # symbol.

51. When is a “switch” statement preferable over an “if” statement?

The switch statement is best used when dealing with selections based on a single
variable or expression. However, switch statements can only evaluate integer and
character data types.

52. What are global variables and how do you declare them?

Global variables are variables that can be accessed and manipulated anywhere in the
program. To make a variable global, place the variable declaration on the upper portion
of the program, just after the preprocessor directives section.

53. What is gets() function?

The gets() function allows a full line data entry from the user. When the user presses
the enter key to end the input, the entire line of characters is stored to a string variable.
Note that the enter key is not included in the variable, but instead a null terminator \0 is
placed after the last character.

54. How many keywords are there in c programming?

32 keywords.

55. What is identifier?

Identifier is the name of variables, functions and arrays.

56. What are the rules for identifier?

• First character should be an alphabet or underscore.


• Cannot use more than 31 charecters.
• Cannot be used keywords.
• White space is not allowed.

You might also like