01)A preprocessor directive is a message from compiler to a linker.
A.True B.False
Answer: Option B
Explanation:
FALSE
Example: #define symbol replacement
When the preprocessor encounters #define directive, it replaces any occurrence of symbol in the rest of the code by replacement. This replacement can be an statement or expression or a block or simple text.
02)Is there any difference between the two statements?
char *ch = "CstEchPause";
char ch[] = "CstEchPause";
A.Yes
B.No
Answer: Option A
Explanation:
In first statement the character pointer ch stores the address of the string "IndiaBIX".
The second statement specifies the space for 7 characters be allocated and that the name of location is ch.
03)In which order do the following gets evaluated
1. Relational
2. Arithmetic
3. Logical
4. Assignment
2.Arithmetic operators: *, /, %, +, -
1. Relational operators: >, <, >=, <=, ==, !=
3. Logical operators : !, &&, ||
4. Assignment operators: =
04)Declare the following statement?
"A pointer to a function which receives an int pointer and returns float pointer".
A.float *(ptr)*int
B.float *(*ptr)(int)
C.float *(*ptr)(int*)
D.float (*ptr)(int)
Answer: Option C
05)What do the following declaration signify?
void *cmp();
A.cmp is a pointer to an void type.
B.cmp is a void type pointer variable.
C.cmp is a function that return a void pointer.
D.cmp function returns nothing.
Answer & Explanation
Answer: Option C
06)Declare the following statement?
"A pointer to a function which receives nothing and returns nothing".
A.void *(ptr)*int;
B.void *(*ptr)()
C.void *(*ptr)(*)
D.void (*ptr)()
Answer & Explanation
Answer: Option D
07)What do the following declaration signify?
int *f();
A.f is a pointer variable of function type.
B.f is a function returning pointer to an int.
C.f is a function pointer.
D.f is a simple declaration of pointer variable.
Answer & Explanation
Answer: Option B
08)The keyword used to transfer control from a function back to the calling function is
A.switch
B.goto
C.go back
D.return
Answer: Option D
Explanation:
The keyword return is used to transfer control from a function back to the calling function.
Example:
#include<stdio.h>
int add(int, int); /* Function prototype */
int main()
{
int a = 4, b = 3, c;
c = add(a, b);
printf("c = %d\n", c);
return 0;
}
int add(int a, int b)
{
/* returns the value and control back to main() function */
return (a+b);
}
Output:
c = 7
09)The library function used to find the last occurrence of a character in a string is
A.strnstr()
B.laststr()
C.strrchr()
D.strstr()
Answer: Option C
Explanation:
Declaration: char *strrchr(const char *s, int c);
It scans a string s in the reverse direction, looking for a specific character c.
Example:
#include <string.h>
#include <stdio.h>
int main(void)
{
char text[] = "learn through Cstechpause.com";
char *ptr, c = 'i';
ptr = strrchr(text, c);
if (ptr)
printf("The position of '%c' is: %d\n", c, ptr-text);
else
printf("The character was not found\n");
return 0;
}
Output:
The position of 'i' is: 19
10)If char=1, int=4, and float=4 bytes size, What will be the output of the program ?
#include<stdio.h>
int main()
{
char ch = 'A';
printf("%d, %d, %d", sizeof(ch), sizeof('A'), sizeof(3.14f));
return 0;
}
A.1, 2, 4
B.1, 4, 4
C.2, 2, 4
D.2, 4, 8
Answer: Option B
Explanation:
Step 1: char ch = 'A'; The variable ch is declared as an character type and initialized with value 'A'.
Step 2:
printf("%d, %d, %d", sizeof(ch), sizeof('A'), sizeof(3.14));
The sizeof function returns the size of the given expression.
sizeof(ch) becomes sizeof(char). The size of char is 1 byte.
sizeof('A') becomes sizeof(65). The size of int is 4 bytes (as mentioned in the question).
sizeof(3.14f). The size of float is 4 bytes.
Hence the output of the program is 1, 4, 4
A.True B.False
Answer: Option B
Explanation:
FALSE
Example: #define symbol replacement
When the preprocessor encounters #define directive, it replaces any occurrence of symbol in the rest of the code by replacement. This replacement can be an statement or expression or a block or simple text.
02)Is there any difference between the two statements?
char *ch = "CstEchPause";
char ch[] = "CstEchPause";
A.Yes
B.No
Answer: Option A
Explanation:
In first statement the character pointer ch stores the address of the string "IndiaBIX".
The second statement specifies the space for 7 characters be allocated and that the name of location is ch.
03)In which order do the following gets evaluated
1. Relational
2. Arithmetic
3. Logical
4. Assignment
2.Arithmetic operators: *, /, %, +, -
1. Relational operators: >, <, >=, <=, ==, !=
3. Logical operators : !, &&, ||
4. Assignment operators: =
04)Declare the following statement?
"A pointer to a function which receives an int pointer and returns float pointer".
A.float *(ptr)*int
B.float *(*ptr)(int)
C.float *(*ptr)(int*)
D.float (*ptr)(int)
Answer: Option C
05)What do the following declaration signify?
void *cmp();
A.cmp is a pointer to an void type.
B.cmp is a void type pointer variable.
C.cmp is a function that return a void pointer.
D.cmp function returns nothing.
Answer & Explanation
Answer: Option C
06)Declare the following statement?
"A pointer to a function which receives nothing and returns nothing".
A.void *(ptr)*int;
B.void *(*ptr)()
C.void *(*ptr)(*)
D.void (*ptr)()
Answer & Explanation
Answer: Option D
07)What do the following declaration signify?
int *f();
A.f is a pointer variable of function type.
B.f is a function returning pointer to an int.
C.f is a function pointer.
D.f is a simple declaration of pointer variable.
Answer & Explanation
Answer: Option B
08)The keyword used to transfer control from a function back to the calling function is
A.switch
B.goto
C.go back
D.return
Answer: Option D
Explanation:
The keyword return is used to transfer control from a function back to the calling function.
Example:
#include<stdio.h>
int add(int, int); /* Function prototype */
int main()
{
int a = 4, b = 3, c;
c = add(a, b);
printf("c = %d\n", c);
return 0;
}
int add(int a, int b)
{
/* returns the value and control back to main() function */
return (a+b);
}
Output:
c = 7
09)The library function used to find the last occurrence of a character in a string is
A.strnstr()
B.laststr()
C.strrchr()
D.strstr()
Answer: Option C
Explanation:
Declaration: char *strrchr(const char *s, int c);
It scans a string s in the reverse direction, looking for a specific character c.
Example:
#include <string.h>
#include <stdio.h>
int main(void)
{
char text[] = "learn through Cstechpause.com";
char *ptr, c = 'i';
ptr = strrchr(text, c);
if (ptr)
printf("The position of '%c' is: %d\n", c, ptr-text);
else
printf("The character was not found\n");
return 0;
}
Output:
The position of 'i' is: 19
10)If char=1, int=4, and float=4 bytes size, What will be the output of the program ?
#include<stdio.h>
int main()
{
char ch = 'A';
printf("%d, %d, %d", sizeof(ch), sizeof('A'), sizeof(3.14f));
return 0;
}
A.1, 2, 4
B.1, 4, 4
C.2, 2, 4
D.2, 4, 8
Answer: Option B
Explanation:
Step 1: char ch = 'A'; The variable ch is declared as an character type and initialized with value 'A'.
Step 2:
printf("%d, %d, %d", sizeof(ch), sizeof('A'), sizeof(3.14));
The sizeof function returns the size of the given expression.
sizeof(ch) becomes sizeof(char). The size of char is 1 byte.
sizeof('A') becomes sizeof(65). The size of int is 4 bytes (as mentioned in the question).
sizeof(3.14f). The size of float is 4 bytes.
Hence the output of the program is 1, 4, 4
0 comments:
Post a Comment