C Programming Upwork Test

0
406

We don’t guarantee that all provided answers are correct.

Where is the file searched, when #include is used with angular brackets <>?
Answer

  • System libraries
  • The current source directory
  • Both of the above

What will be the output of the following code?
int main()
{
int a=5;
if(a=10)
printf(“value of a=%d”,a);
else
printf(“value of the a=%d”,a);
return 0;
}
Answer

  • value of a=5
  • value of a=10
  • value of a=0
  • 10

The offset used in fseek() function call can be a negative number.
Answer

  • True
  • False

What will happen if in a c program you assign a value to an array element whose subscript exceeds the size of array?
Answer

  • The compiler would report an error
  • The element will be set to 0
  • The program may crash if some important data gets overwritten
  • The array size would appropriately grow

Which of the following is used to convert a C program into machine language for execution?
Answer

  • Compiler
  • Interpreter
  • Assembler
  • Editor

Which of the following is used for dynamically allocating memory?
Answer

  • malloc() and memalloc()
  • alloc() and memalloc()
  • malloc() and calloc()
  • memalloc() and faralloc()

Point out the error in the program?
typedef struct data mystruct;
struct data
{
int x;
mystruct *b;
};
Answer

  • Error: in structure declaration
  • Linker Error
  • No Error
  • None of above

A pointer is a special kind of variable which is used to store the ___ of a variable.
Answer

  • Data Type
  • Variable Name
  • Address
  • Value

What is argc used for?
Answer

  • It points to each argument passed to the program
  • It is the number of arguments passed to the program
  • It is the arguments of type command line
  • It counts the memory occupied by all the arguments

C preprocessors can have compiler specific features.
Answer

  • true
  • false
  • Depends on the standard
  • Depends on the platform

Which of the following correctly shows the hierarchy of the arithmetic operator in C?
Answer

  • / + * –
  • * – / +
  • + – / *
  • / * + –

Which function is used to check if the end of the file has been reached in C?
Answer

  • fscanf()
  • feof()
  • fclose()
  • fgets()

What is the output of the following code?
void myFunction(int foo[2][3])
{
foo[0][1] =5;
int i =0, j=0;
for(i=0;i<2;i++)
for(j=0;j<3;j++)
printf(“%d”, foo[i][j]);
}
int main()
{
int foo[2][3] =={0};
myFunction(foo);
return 0;
}
Answer

  • 0 5 0 0 0 0
  • Error
  • garbage 5 garbage garbage garbage garbage
  • Nothing

What is the output of the following program?
int main ()
{
int foo = 1;
Do {
printf(“%d”,foo);
foo+;
} while( foo<=10)
return 0;
}
Answer

  • 1 2 3 4 5 6 7 8 9 10
  • 1 1 1 1 1 1 1 1 1 1 1
  • The program will not execute due to an error

What is the output of the following code?
int main()
{
FILE *foober = stdout;
int foo;

fprintf(foobar , %d”, 20);
fflush(stdout);
fprintf(stderr, “%d”, 99);
return 0;
}
Answer

  • 2099
  • 20 99
  • 99
  • 20
  • Code will throw an error

Which of the following is a correct format for declaration of a function?
Answer

  • return_type function-name(argument type);
  • return-type function-name(argument type){}
  • return-type(argument type)function-name;
  • Both 1 and 2

In the following code, p2 is integer pointer or integer?
typedef int*ptr;
ptr p1,p2;
Answer

  • Integer
  • Integer pointer
  • Error in declaration
  • None of the above

What type of array is the generally generated in a Command-line argument?
Answer

  • Single dimension array
  • 2-Dimensional square array
  • 2-Dimensional rectangular Array
  • Jagged Array

Which of the following C preproccessor?
Answer

  • ifdef
  • #define
  • #endif
  • All of the mentioned

Which keyword is used declare a variable so that the variable can be accessed by all the function in all the modules of a program?
Answer

  • extern
  • register
  • const
  • static

Which of the following function can be used to set the file indicator to the beginning of the file?
Note: There may be more than one right answer
Answer

  • fseek()
  • rewind()
  • feof()
  • ftell()

Which of the following is a correct way to initialize the array?
Answer

  • int n[6]={2, 4, 12, 5, 45, 5};
  • int n{}={2, 4, 12, 5, 45, 5};
  • int n{6}={2, 4, 12};
  • int n(6)={2, 4, 12, 5, 45, 5};

The prototype of a function can be used to:
Answer

  • Define function
  • Erase a function
  • Declare a function
  • None of the above

How will you free the allocated the memory?
Answer

  • remove the (var-name)
  • free(var-name)
  • delete (var-name)
  • dalloc(var-name)

Point out the error in the following program (if it is compiled with Turbo-C compiler)?
#include
int main()
{
display();
return 0;
}
void display()
{
printf(“Upwork.com”);
}
Answer

  • No error
  • display() does not get invoked
  • display() is called before it is defined
  • None of the above

What does the following declaration signify?
char *arr[10];
Answer

  • arr is an array of 10 character pointers
  • arr is an array of function pointer
  • arr is an array of characters
  • arr is a pointer to array of characters

What will be the output of the program (myprog.c) given below if it is executed from the command line?
cmd > myprog one two three
/* myprog.c */
#include
int main(int argc, char **argv)
{
printf(“%c\n”, **++argv);
return 0;
}
Answer

  • myprog one two three
  • myprog one
  • 0 =
  • two

#pragma exit is the primarily used for?
Answer

  • Checing memory leaks after exiting the program
  • Informing operating system that program has terminated
  • Running a function at exiting the program
  • No such preprocessor exist

What will be the output following program?
#include<stdio.h>
int main()
{
int y=128;
const int x=y;
printf(“%d\n”,x);
return 0;
}
Answer

  • 128
  • Garbage value
  • Error
  • 0

Which of the following is the correct syntax to open a file append mode?
Answer

  • foo = fopen (“bar.txt”,”w+”);
  • foo = fopen (“bar.txt”, “e”);
  • foo = fopen (“bar.txt”, “r+”);
  • foo = fopen (“bar.txt”, “w”);
  • foo = fopen (“bar.txt”, “r”);

What is actually passed to a function when you pass it an array?
Answer

  • A copy of the element of the array
  • A copy of all the element of the array
  • The address of the first element of the array
  • The address of the last element of the array

If the storage size of unsigned int is 2 bytes, then the range of values of an unsigned integer is:
Answer

  • 0 to 65,535
  • 0 to 255
  • 0 to 32,767
  • 0 to 2

If the two strings are identical, the strcmp() function returns?
Answer

  • -1
  • 0
  • 1
  • yes

Which keyboard is used to transfer control from a function back to the calling function?
Answer

  • switch
  • goto
  • go back
  • return

Assuming integer takes 4 bytes and starting address of the array ‘foo’ is 2000, what will be the output of the following code?
Answer
int main()
{
int foo[2][3][4][5];
foo[2][3][4][5]=50;
printf(“%d”,*(*(*(*(foo+2)+3)+4)+5));
return 0;
}
Answer

  • 50
  • 2000
  • 2014
  • 2056
  • 64

When a program uses command line argument, then argv[0]?
Answer

  • is a pointer to the first command line argument supplied
  • refers to the number of arguments passed
  • holds the name of the program itself
  • is null

In which stage the following code:
#include<stdio.h>
gets replaced by the contents of the file stdio.h?
Answer

  • During Editing
  • During linking
  • During execution
  • During preprocessing

Which type of files cannot be opened using fopen()?
Answer

  • .txt
  • .bin
  • .c
  • None of the mentioned

Array elements are always stored in______memory location.
Answer

  • Sequential
  • Random
  • Sequential and Random
  • None of the above

Consider the following definition of a Union MyUnion, if int occupies 4 bytes, what is the memory size occupied by a variable of type MyUnion?
union MyUnion {
int foo;
float bar;
chat foobar[16];
}
Answer

  • 16
  • 20
  • 24
  • 28

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.