You are on page 1of 10

Complex Questions:

Q1. what is the difference between "Declaration" and "definition" of a


variable ?

Q1-Ans:

A declaration announces the properties of a variable (its type);


A definition also causes storage to be set aside.

Example:

In case of extern specifier...


the extern variables are declared in one file, and can be defined else where.

file 1: ( Declaration is done :- No storage is allocated )


extern int ProcessId;
extern double check[];

file 2: (Defined and also initialized)

int ProcessId=0;
double check[MAXVAL];

Q2. What is "auto" storage class specifier?

Q2-Ans:

The auto and register specifiers give the declared objects automatic storage
class, and maybe used only with in functions.
These declarations also serve as definitions and cause storage to be
reserved.

Register specifier is used for specific values only which is implementation-


dependent.

Q3. define a macro for an infinite loop?


Q3-Ans:

#define infinite for(; ;) /* infinite loop*/

Q4. what is the difference between

int (*DayofMonth)[13];
and int *Dayofmonth[13];

Q4-Ans:

a) the first one indicates a pointer named (DayofMonth) to 13 integers.

b) the second one indicates there are 13 pointers to integers.

Reason: [] has more precedence over *.

Q5. what does the function strstr() does?

Q5-Ans:

syntax :- void *strstr(char *src, char *tok);


strstr(s,t) returns a pointer to the first occurance of the string t in the strings,
or NULL if there is none.

Q6. what is the difference between (*++Local)[0] and **++Local.

Q6-Ans:

They are the same...

Q7. what does system command do?

Q7-Ans:

Syntax: int system(const char *s)

system passes the string s to the environment for execution. If S is NULL,


system returns non-zero, if S is not NULL, the return value is
implementation-dependent.
Q8. Using the following example answer the questions.

Example:

int amt[2][3][2]= {
{
{12,14},
{15,16},
{17,18}
},
{
{19,20},
{21,22},
{23,24}
}
};

a) what is the value of amt ?


b) what is the value of *amt?
c) what is the value of **amt?
d) what is the value of ***amt?
e) what is the value of **amt +1?

Q8-Ans:

a) amt= memory adress of {12},


b) *amt = memory adress of first element {12}
c) **amt = same as above.
d) ***amt = value of the first element a[0][0][0] = 12.
e) **amt+1 will point to memory adress of {14}.

Q9. what does asctime function do?

Q9-Ans:

syntax: char *asctime(const struct tm *tp);


asctime converts the time in the structure *tp into a string of the form

Sun Jan 3 15:14:13 1988\n\0

Q10. what does ungetc() function do?

Q10-Ans:

syntax :- int ungetc(int c, FILE * stream)

ungetc pushes c (converted unsigned char) back onto stream. This character
will be returned on the next read.

Q11. How do variable arguments are handled in a function?

Q11-Ans:

Pointers and variable number of arguments are handled from "stdarg.h"


include file.

lnclude file "stdarg.h" contains macros va_start, va_arg and va_list used to
solve the variable number of arguments passed to a function.

ex: printf() takes variable number of arguments.


Medium Complex Questions:

Q1. define a macro for finding the maximum of three numbers A, B, C?

Q1-Ans:

#define Max_two(A,B) ((A) > (B) ? (A) : (B))


#define Max_three(A,B,C) ( Max_two(A,B) > (C) ? Max_two(A,B) : (C))

Q2. what is the purpose of declaring a function static in C?

Q2-Ans:

syntax: static function_name (argumants){ }

If static is used, the function can be called only by any other function with in
the File. No other function from another file can call this.

Q3. what *--ptr , *ptr++ does?

Q3-Ans:

a) It first decrements the pointer before pointing to the Data Object.


b) The increment is done later.

ex: *p++ = val; /* Pushing value to a stack */


val_ret = *--p ; /* pop top of the stack into val */

Q4. Write an alogorithm to find out the number of 0's and 1's in a given
number?

Q4-Ans:

step 1: The input number is assigned to a variable.


step 2: Loop until the variable value becomes 0.
step 2 : Using right shift, the value is fetched in an unsigned int (short)
variable.
step 3: Divide the new unsigned variable with 2, find out whether the
number is odd or even.

(alternate) : Doing "AND" with value 1, fetches the result as odd or even.
step 4: Display the count of 1's and 0's.

Q5. C and Unix. (One process is opening and writing a file which is
more than 2 GB ). If the file size is limited to 2GB for some machine ,
how should we solve this situation??

Q5-Ans:

-Algorithm:-
1. Open new file.
2. call "system" function to do the following.
cat 'old_file' >> new_file.
trunc old_file,
3. close the new_file.
4. Find that fseek(FILE *stream) is pointed to 0th position.
5. Start writing from 0th position.

Q6.what does realloc function does?

Q6-Ans:

syntax: void *realloc(void *p, size_t size)

realloc changes the size of the object pointed to by p to size. the contents are
unchanged. If the new size is larger, the new space is uninitialized.
new size cannot be smaller.

Q7. what is Null Directive?

Q7-Ans:

A preprocessor of the form

#
has no effect on the program code.

Q8. What does this statement do void *calloc(size_t nobj, size_t size)?
Q8-Ans:

calloc returns a pointer to space for an array of "nobj" objects , each of size
size. or NULL if request failed. The space is initialized to zero bytes.

Q9. What does this statement do void *malloc(size_t size)?

Q9-Ans:

malloc returns a pointer to space for an object of size size. the space is
uninitialized.

Q10. what is the return value of fork?? ( function of C in unix)

Q10-Ans:

Fork if successful, returns value 0 to the child Process .


returns value child PID to the parent process.

Q11. Write a pointer version of strcpy ?

Q11-Ans:

ans : void strcpy (char *s, char *t)


{
while (*s++ = *t++ );
}

Q12. What is the use FTELL function?

Q12-Ans:

syntax :- long ftell(FILE * stream)

ftell returns the current file position for stream., -1L on Error.

Q13. what is the use of clearer function?

Q13-Ans:

syntax : void clearerr(FILE * stream)


clearerr clears the End of file (eof) and Error indicators for Stream.

Q14. How do u declare a pointer to function?

Q14-Ans:

main()
{
int *p;
int (*func_ptr) (); /* prototype declaration , tells the compiler that
there is a pointer to function coming ahead.*/

p=func_ptr(); /* assign address of function */


Printf("\n address of pointer to function = %u",p);
}

int *func_ptr()
{
printf( " This is to test Pointers to functions\n");
}
Normal Questions:
Q1. what does function labs (long n) do?

Q1-Ans:

labs returns the absolute value of its long argument.

Q2. what does getche() function do? ( #include <conio.h>)

Q2-Ans:

This function echos the input character when pressed from an input device.
No need to give ENTER.

Q3. int a =3,*j,*z;

j=&a;
z=&j;

what will be the values of a, j, z?

Q3-Ans:

a=3; j= (address of a);


z= (address of j);

Q4. what is the difference between "r" and "r+" in file operations?

Q4-Ans:

"r" -- open text file for reading.


"r+" -- open text file for update (i.e., reading or writing).

in the same way:

"w" -- create text file for writing, discard previous contents if any.
"w+" -- create text file for update; discard previous contents if any.
same with append "a" -- append at the end of file for writing.
"a+" -- append at the end of file for updating.

differences of r+ , w+... :
r+ cannot create a file for writing.
w+ will create a file if the file-name does not exist.

Q5. printf -- function formatting questions.

%-2f -- minus prefix specifies left adjustment of the converted


argument in its field.

%+d -- Plus prefix specifies that the number will always be printed
with a sign.

%0d -- zero prefix specifies padding to the field width with leading
zeros.

You might also like