Thursday, November 10, 2016

C Programming Test 2016 – Upwork Test Answers

Upwork C Programming Test 2016...

43 Answered Test Questions:
 
1. Identify the incorrect statement.
Answers:
a. Records can be defined in C by using structures
a. Structure members can be of the same/different data types
a. Memory is reserved when a structure label is defined
a. A pointer to a structure can be used to pass a structure to a function
a. Arrays of structures can be defined and initialized
2. What will be printed on the standard output as a result of the following code snippet?
void func()
{
static int i = 1;
int j = 1;
i++;
j++;
printf(“%d %d “,i,j);
}
void main()
{
func();
func();
func();
}
Answers:
a. 2 2 2 2 2 2
a. 2 2 3 2 4 2
a. 2 2 2 3 2 4
a. 2 2 3 3 4 4
a. None of these
3. Given the following array:
int a[8] = {1,2,3,4,5,6,7,0};
what would be the output of
printf(“%d”,a[4]); ?
Answers:
a. 3
a. 4
a. 5
a. 6
a. 7
4. Which function will convert a string into an integer?
Answers:
a. int()
a. number()
a. atoi()
a. val()
a. tonum()
5. Which standard function is used to clear memory allocated by the malloc() function?
Answers:
a. free
a. calloc
a. delete
a. elease
a. destroy
6. From which of the following loop or conditional constructs, is “break” used for an early exit?
Answers:
a. switch
a. fo
a. while
a. do-while
a. All of the above
7. What would be printed on the standard output as a result of the following code snippet?
char i = ‘A’;
char *j;
j = & i;
*j = *j + 32;
printf(“%c”,i);
Answers:
a. An error will occur
a. a
a. A
a.
a. c
8. What does the argv[0] represent?
Answers:
a. The first command line parameter has been passed to the program
a. The program name
a. The number of command line arguments
a. None of the above
9. What would be printed on the standard output as a result of the following code snippet?
#define func(t, a, b) { t temp; temp=a; a=b; b=temp; }
main()
{
int a=3, b=4;
float c=4.5, d = 5.99;
func(int, a, b);
func(float, c, d);
printf(“%d %d “, a, b);
printf(“%.2f %.2f\n”, c, d);
}
Answers:
a. Results in Compilation Error
a. 3 4 5.99 4.50
a. 3 4 4.50 5.99
a. 4 3 5.99 4.50
a. None of the above
10. What is the function to concatenate two strings?
Answers:
a. strcmp()
a. strcpy()
a. strcat()
a. strlen()
a. catstr()
11. Given the following array:
char books[][40]={
“The Little World of Don Camillo”,
“To Kill a Mockingbird”,
“My Family and Other Animals”,
“Birds, Beasts and Relatives”
};
what would be the output of printf(“%c”,books[2][5]);?
Answers:
a. m
a. M
a. F
a. i
a. L
12. Which of the following is not a valid mode for opening a file?
Answers:
a. r
a. w
a. a
a. +
a. i
13. Given the following array declaration:
int a[2][3][4]
what would be the number of elements in array a?
Answers:
a. 24
a. 22
a. 20
a. 12
a. 36
14. Which function will convert a string into a double precision quantity?
Answers:
a. atoi()
a. atof()
a. atol()
a. atan()
a. acos()
15. What will be the output of following code?
int main()
{
int i;
i = 0;
for (i = 1; i <2; i++)
{
i++;
printf( “%d”, i );
continue;
printf( “%d”, i );
}
return 0;
}
Answers:
a. 22
a. 2,2
a. 2
a. none of the above
16. What would be printed on the standard output as a result of the following code snippet?
main()
{
int u = 1, v = 3;
printf(“%d %d”,u,v);
funct1(&u,&v);
printf(“%d %d\n”,u,v);
}
void funct1(int *pu, int *pv)
{
*pu=0;
*pv=0;
return;
}
Answers:
a. 1 31 3
a. 1 3 1 1
a. 1 30 0
a. 1 1 1 1
a. 3 1 3 1
17. What will be printed on the standard output as a result of the following code snippet?
void main()
{
int num1 = 30, num2 = 4;
float result;
result = (float)(num1/num2);
printf(“%.2f”, result);
return 0;
}
Answers:
a. 7
a. 7.00
a. 7.000000
a. 7.5
a. 7.50
18. Study the following code:
int n = 2;
int a[n];
What is the error in the above code?
Answers:
a. There is no error
a. The minimum limit of an array is 5
a. The second statement should be placed before the first
a. A constant value has to be given in place of a variable for array declaration
19. Which of the following is not a file related function?
Answers:
a. fgetc()
a. puts()
a. fputc()
a. fscanf()
a. fprintf()
20. What is the output of the following program ?
main()
{
int u = 1, v = 3;
printf(“%d %d”,u,v);
funct1(&u,&v);
printf(” %d %d\n”,u,v);
}
void funct1(int *pu, int *pv)
{
*pu=0;
*pv=0;
return;
}
Answers:
a. 1 3 1 3
a. 1 3 1 1
a. 1 3 0 0
a. 1 1 1 1
a. 3 1 3 1
21. What would be printed on the standard output as a result of the following code snippet?
#include
main()
{
unsigned char a=255;
a = a+1;
printf(“%d”,a);
return 0;
}
Answers:
a. Undefined value
a. 256
a. 1
a. -1
22. What is wrong with the following statement?
int func();
Answers:
a. The function definition {…} is missing
a. While calling a function, the type int is not needed
a. No parameter has been passed
a. The semicolon should not be there
a. There is nothing wrong with the statement
23. Suppose there is a file a.dat which has to be opened in the read mode using the FILE pointer ptr1, what will be the correct syntax?
Answers:
a. ptr1 = open(“a.dat”);
a. ptr1 = fileopen(“a.dat”);
a. ptr1 = fopen(“a.dat”,”r”);
a. ptr1 = open(“a.dat”,”r”);
a. ptr1 = fileopen(“a.dat”,”r”);
24. What would be printed on the standard output as a result of the following code snippet?
main()
{
char *pmessage = “asdfgh”;
*pmessage++;
printf(“%s”, pmessage);
return 0;
}
Answers:
a. Will result in Compilation Error
a. Undefined string
a. sdfgh
a. asdfgh
25. Study the following code where num is an integer array and n is the length of the array:
for(i=0;i<n-1;i++)
{
for(j=i+1;j<n;j++) { if(num[i] > num[j])
{
var=num[i];
num[i]=num[j];
num[j]=var;
}
}
}
What does the above code do?
Answers:
a. It prints the elements of the array in the ascending orde
a. It calculates the sum of the elements of the array
a. It sorts the array in the ascending orde
a. It sorts the array in the descending orde
a. It calculates the average of the elements of the array
26. Read the following two declaration statements.
1. #include
2. #include “stdio.h”
Which of the following statements pertaining to the above two statements are correct?
Answers:
a. For statement 1, the header file will be searched first in the local directory and then in the standard system directories such as “/usr/include”
a. For statement 1, the header file will be searched in the standard system directories such as “/usr/include”
a. For statement 2, the header file will be searched first in the local directory and then in the standard system directories such as “/usr/include”
a. For statement 2, the header file will be searched in the standard system directories such as “/usr/include”
a. None of the above
27. Is the following statement correct? If not, why not? If yes, what is the size of the array?
int array[][3] = { {1,2}, {2,3}, {3,4,2} };
Answers:
a. Yes, the size is three columns by two rows
a. Yes, the size is two columns by two rows
a. No, the first dimension is omitted
a. No, one of the three initializer sets contains too many numbers
a. Yes, the size is three columns by three rows
28. What would be printed on the standard output as a result of the following code snippet?
#define max(a, b) ((a) > (b)?(a):(b))
main()
{
int a=4;
float b=4.5;
printf(“%.2f\n”,max(a, b));
}
Answers:
a. Results in Compilation Error
a. Undefined value
a. 4.50
a. 4.0
a. None of the above
29. What will be the output of the following program?
#include
main()
{
int n = 5;
assert(n > 3); //statement 1
n = n+2;
assert(n > 7);//statement 2
return 0;
}
Answers:
a. Assertion ‘n > 3’ failed; Program aborts at statement 1
a. Assertion ‘n > 7’ failed; Program aborts at statement 2
a. Program returns 0 with the value of n as 7
a. Compilation Error
30. What would be printed on the standard output as a result of the following code snippet?
main()
{
enum {red, green, blue = 6, white};
printf(“%d %d %d %d”, red, green, blue, white);
return 0;
}
Answers:
a. 0 1 6 2
a. 0 1 6 7
a. Will result in Compilation Error
a. None of the above
31. Which file header is to be included for file handling in a C program?
Answers:
a. string.h
a. file.h
a. stdio.h
a. stdlib.h
a. ctype.h
32. What will be printed on the standard output as a result of the following code snippet?
void main()
{
char arr[] = {‘R’,’A’,’M’};
printf(“%d”,strlen(arr));
}
Answers:
a. 1
a. 3
a. 4
a. Cannot be determined
33. Which function will you use to write a formatted output to the file?
Answers:
a. fputc()
a. fputs()
a. fprintf()
a. fseek()
a. ftell()
34. Which function returns the current pointer position within a file?
Answers:
a. ftell()
a. fseek()
a. fgetc()
a. fread()
a. fscanf()
35. Which of the following is not a string function?
Answers:
a. strlen()
a. strcmp()
a. strcpy()
a. strrev()
a. strcomp()
36. Which of the following declarations of structures is/are valid?
1)
struct node {
int count;
char *word;
struct node next;
}Node;
2)
struct node {
int count;
char *word;
struct node *next;
}Node;
3)
struct node {
int count;
char *word;
union u1 {
int n1;
float f1;
}U;
}Node;
Answers:
a. 123
a. 12
a. 23
a. 2
a. None of the above
37. What would be printed on the standard output as a result of the following code snippet?
main()
{
int arr[10];
int a = sizeof(arr);
printf(“%d\n”,a);
return 0;
}
Answers:
a. Compilation Error
a. 10
a. 4
a. 40
38. Which of the following is a function for formatting data in memory?
Answers:
a. sprintf()
a. printf()
a. scanf()
a. free()
a. atol()
39. Which function allocates memory and initializes elements to 0?
Answers:
a. assign()
a. calloc()
a. malloc()
a. swab()
a. allocate()
40. What will be printed on the standard output as a result of the following code snippet?
void main()
{
int i,j,k;
i=4;
j=30;
k=0;
k=j++/i++;
++k;
printf(“%d %d %d”,i,j,k);
}
Answers:
a. 5 31 8
a. 5 31 7
a. 5 31 6
a. 4 30 7
41. Given the operators:
1) *
2) /
3) %
What would be the order of precedence?
Answers:
a. 1,2,3
a. 1,3,2
a. 3,2,1
a. All have the same precedence
a. 1 and 2 have the same precedence, 3 is of lower precedence
42. Which of the following sets of conversion statements may result in the loss of data?
Answers:
a. int i; char c; i=c; c=i;
a. int i; char c; c=i; i=c;
a. int i; float f; i=f; f=i; 
a. None of the above
43. Which of the following standard functions is used to close a file?
Answers:
a. fileclose()
a. closefile()
a. fclose()
a. Any of the above

No comments:

Post a Comment

Earn for Free

http://hiredrmjru.trade/3670784521590/