Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Ans: Microcontrollers are designed for embedded applications, whereas microprocessors are used in
Ans: Compiler translates the entire source program into object program at once and then the object
On the other hand, Interpreter translates one line of source code at a time and then executes it
Q3: Can we use “int” data type to store the value 32768? Why?
Ans: No. “int” data type can be used to store values from -32768 to 32767. To store 32768, we can
Q4: What is the difference between the statements “b = ++a;” and “b = a++;”?
Ans: The first statement employs prefix notation. It can be broken down into two statements a = a +
1 followed by b = a. Hence a will be incremented first and will then be assigned to b. Thus, values of
The second statement employs postfix notation. It can be broken down into two statements b = a
followed by a = a + 1. Hence a will be assigned to b. Only after this assignment a will be incremented.
int=10;
Ans: No. “int” is a reserved word in C and cannot be used as a user-defined variable.
FLOAT = 10;
Ans: Yes. We might think that FLOAT is a reserved word which cannot be used for declaring
variables. But reserved words in C are in lower case and thus “FLOAT” will not be interpreted as a
reserved word.
Ans: Yes. If the program is written for a freestanding environment, then main() function is not
required. Freestanding environments are those where the program does not depend on any host
and can have any other function designated as the startup function. Examples of freestanding
Ans: We should not use type casting to override a “const” or “volatile” declaration. Overriding these
Ans: getch() captures a single character from the keyboard and assigns it to a variable, without
getche() captures a single character from the keyboard and assigns it to a variable, and also displays
printf(“10%%”);
Q12: What will happen if a break statement is omitted in any case of a switch statement?
Ans: If a break statement is omitted in any case of a switch statement, the compiler will not issue an
error message. The flow of control will continue to the next case label, probably causing an incorrect
output.
int a[20];
Ans: No, the compiler will not show any error as C does not check the validity of the array index
neither at compile time nor at run time, but the result of running such a code is totally
unpredictable.
Q14: How can we determine whether a character is numeric, alphabetic, and so on?
Ans: The header file ctype.h defines various functions for determining what class a character belongs
to. For example, isdigit() returns a non-zero value if argument is a digit (0 – 9) and isalpha() returns a
Q15: What is the difference between Call by Value and Call by Reference?
Ans: By using Call by Value, we can send the value of the variable as parameter to a function,
whereas by using Call by Reference, we can send the address of the variable to a function.
Also, under Call by Value, the value of the parameter is not affected by whatever operation that
takes place within the function, while in the case of Call by Reference, values can be affected by the
Ans: No. ++*ptr can be interpreted as ++(*ptr). Thus, it increments the value being pointed to by ptr.
*ptr++ can be interpreted as *(ptr++).Thus it increments the value of pointer ptr and not the value
pointed by it.
Ans: calloc(...) takes in two arguments: the first for the number of elements to be allocated and the
second for the size of each element. By default the bits in the allocated space are initialized to 0.
malloc(...) takes in only a single argument which is the memory required in bytes. It does not
Ans: A structure variable contains each of the named members, and its size is greater or equal to the
A union variable contains one of the named members at a given time and its size is same as that of
#include <file_name>
and
#include “file_name”
The first form is used for referring to the standard system header files. It searches for a file named
file_name in a standard header file library and inserts it at the current location.
Ans: In C, a pointer may be used to hold the address of dynamically allocated memory. After this
memory is freed with the free() function, the pointer itself will still contain the address of the
released block. This is referred to as a dangling pointer. Using the pointer in this state is a serious
programming error. Pointers should be assigned 0 or NULL after freeing memory to avoid this bug.
Ans: A pointer which has not been initialized is known as a wild pointer.
void main()
int *ptr;
printf("%u\n",ptr);
printf("%d",*ptr);
Garbage value
Ans: The size of any type of pointer in C is independent of data type that the pointer is pointing to.
The size of all type of pointers in C is either two bytes or four bytes (depending on the compiler),
irrespective of whether it is a char pointer, double pointer, function pointer, or null pointer. Void
pointer is no exception to this rule and size of void pointer is also of either two or four bytes.
Q23: Can a C program be invoked from another C program? If yes, how it can be done?
Ans: Yes, a C program can be invoked from another program using system calls.
Q25: Can a file other than a “.h” file be included with #include directive?
Ans: The preprocessor will include whatever files we specify in #include statement. Therefore, if we
have the line #include <macro.inc> in our program, the file “macros.inc” will be included in our
precompiled program.
We should always put a “.h” extension on any of the C files that we are going to include. This
method makes it easier for others to identify which files are being used for preprocessing purposes.
For instance, someone modifying or debugging our program might not know to look at the
macros.inc file for macro definitions. That person might try in vain by searching all files with .h
extensions and come up empty. If our file had been named macros.h, the search would have
included the macros.h file, and the searcher would have been able to see what macros we defined in
it.
Ans: NULL is defined as either 0 or (void*)0. These values are almost identical: either a literal zero or
a void pointer is converted automatically to any kind of pointer, as necessary, whenever a pointer is
needed (although the compiler can’t always tell when a pointer is needed).
Ans: Yes, it is possible to create a customized header file. We can include the function prototypes
that we want to use in our program in it, and then use the #include directive followed by the name
For example: anyNum = rand() will generate any integer number beginning from 0, assuming that
Q29: Some coders debug their programs by placing comment symbols on some codes instead of
Ans: Placing comment symbols /* */ around a code, also referred to as “commenting out”, is a way
of isolating some codes that we think are causing errors in the program, without deleting the code.
The idea is that if the code is in fact correct, we can simply remove the comment symbols and
continue on. It also saves time and effort on having to retype the codes if we have deleted it in the
first place.
Q30: What is the difference between an internal static and an external static variable?
Ans: An internal static variable is declared inside a block with static storage class whereas an
An internal static variable has persistent storage, block scope, and no linkage. An external static
Ans: No, pointers are not integers. A pointer is an address. It is merely a positive number and not an
integer.
Q32: Which directive can be used to avoid multiple inclusions of a header file?
Ans: #ifndef preprocessor directive can be used to avoid multiple inclusions of a header file. For
example, the following code includes "headerfile.h" only if it is not already included.
#ifndef headerfile.h
#define headerfile.h
#endif
Q33: What is the cyclic property of data type in C? Explain with an example.
void main()
printf("%d %d",c1,c2);
This situation is known as overflow of signed char. Range of unsigned char is -128 to 127. If we assign
a value greater than 127, then value of variable will be changed to a value if we move along
clockwise direction as shown in the figure. If we assign a number which is less than -128 then we
Q34: Write a C program to print “Hello world” without using any semicolon.
Ans:
void main()
if(printf("Hello world"))
void main()
int *p;
p=&a;
(*p)++;
Ans: Compiler will generate an error: Cannot modify a constant value. “a” is a constant integer and
myName = “Robin”;
Ans: No. We cannot use the “=” operator to assign values to a string variable. Instead, we can use
if (x<=1)
recur=1;
else
recur=recur(x–3)+recur(x-1);
What would the value of recur if we call the function recur (6)?
Ouput: 9
void main()
int a;
printf("The number printed on screen =%d", scanf("%d", &a)); // value 20 is given as input here
scanf() returns the number of input fields successfully scanned, converted, and stored. In this case
void main()
struct XX
int a=3;
};
printf("%d",s->a);
printf("%s",s->name);
Ans: Compiler error. We cannot initialize structure members inside the structure declaration.
void main()
char *str1=“ABCD”;
char str2[]=“ABC”;
str1 is a character pointer; thus sizeof(str1) gives the size of the pointer variable. It could be 4 or 2
Str2 is a character array with size 4 (including the terminating character '\0').