a) Give any two features of preprocessors.
b) Give the syntax for opening File.
c) Write the syntax of pointer declaration.
d) Write the syntax of union?
e) Give the syntax for macro declaration.
f) What is difference between printf() and fprintf()?
g) Declaration syntax of realloc() function.
h) What is the difference between malloc() and calloc()?
i) Give the syntax getw() and putwo.
Answers
Answer:
Explanation:
a) Features of preprocessor - i) It replaces comments with whitespace ii) It expands macros
b) fptr = fopen(filename, "r") - Opening of file in C
c) int *ip // pointer to integer variable
float *fp; // pointer to float variable
double *dp; // pointer to double variable
char *cp; // pointer to char variable
d) Syntax:
union tag_name
{
data type var_name1;
data type var_name2;
data type var_name3;
};
e) You can also create own header file for custom function declaration and include it in your program using this preprocessor directive.
#include "my_header.h"
f) printf function is used to print character stream of data on stdout console. fprintf is used to print the string content in file but not on stdout console.
g) void *realloc(void *ptr, size_t size);
h) malloc() allocates single block of memory however calloc() allocates multiple blocks of memory with each of same size and it sets all bytes to zero
i) putw(i, fp) here
i – integer value
fp – file pointer
int getw(FILE *fp)