UpWork (oDesk) & Elance C Programming Test Question & Answers
UpWork (oDesk) & Elance C Programming Test Question & Answers are really very important to pass UpWork & Elance test. You will get top score at this skill test exam. If you found any problem or wrong answer please inform me via contact or comments. We will try to solve it in short. This test is extremely valuable to acquire knowledge of C Programming. Lets Start test.
Ques : Which of the following statements will result in a compilation error?
Ans : int n=5, x; x= ++n++;
int n=5, x; x= (n+1)++;
int n=5, x=6; x= (n+x)++;
Ques : Which of the following statements are correct for the keyword register?
Ans : It requests that the variable be kept in the CPU register for maximum speed
It does not guarantee that the variable value is kept in CPU register for maximum speed
Ques : Which is/are the type/s of memory allocation that needs/need the programmer to take care of memory management?
Ans : Dynamic memory allocation
Memory allocation on stack
Ques : Given the array:
int num[3][4]= {
{3,6,9,12},
{15,25,30,35},
{66,77,88,99}
};
what would be the output of *(*(num+1)+1)+1?
Ans : 26
Ques : Given the array:
int num[3][4]=
{
{3,6,9,12},
{15,25,30,35},
{66,77,88,99}
};
what would be the output of *(*(num+1))?
Ans : 15
Ques : What would be printed on the standard output as a result of the following code snippet?
main()
{
int i=5;
char option = 5;
switch(option)
{
case '5':
printf("case : 1 \n");
break;
case i:
printf("case : 2 \n");
break;
default:
printf("case : 3 \n");
break;
}
return 0;
}
Ans : Result in compilation error
Ques : What is the return value in case a file is not opened successfully by using fopen()?
Ans : NULL
Ques : What will be the output of following code?
int main()
{
int i;
i = 0;
for (i = 1; i <2 b="" i="">
{
i++;
printf( "%d", i );
continue;
printf( "%d", i );
}
return 0;
}
Ans : 2
Ques : What would be printed on the standard output as a result of the following code snippet?
char *str1 = "Hello World";
strcat(str1, '!');
printf("%s", str1);
Ans : The code snippet will throw a compilation error
Ques : 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]); ?
Ans : 5
Ques : In order to read structures/records from a file, which function will you use?
Ans : fscanf()
Ques : An array is defined with the following statement in a file, file1.c
int a[ ] = { 1, 2, 3, 4, 5, 6 };
In another file, file2.c, the following code snippet is written to use the array a:
extern int a[];
int size = sizeof(a);
What is wrong with the above code snippet?
Ans : An extern array of unspecified size is an incomplete type. The size of the operator during compile time is unable to learn the size of an array that is defined in another file
Ques : What would be printed on the standard output as a result of the following code snippet?
main()
{
char *s="Hello World";
char s1[20], s2[20];
int len = sscanf(s,"%s",s1);
printf("%s : %d", s1, len);
}
Ans : Hello : 1
Ques : 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?
Ans : ptr1 = fopen("a.dat","r");
Ques : 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("%s",books[3]);?
Ans : Birds, Beasts and Relatives
Ques : What would be printed on the standard output as a result of the following code snippet?
void main()
{
unsigned char a=25;
a = ~a;
signed char b = 25;
b = ~b;
printf("%d %d ", a, b);
}
Ans : 230 -26
Ques : 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;
}
Ans : 7.00
Ques : Which of the following is/are the correct signature/s of main with command line arguments?
Ans : int main(int argc, char *argv[])
Ques : From which of the following loop or conditional constructs, is "break" used for an early exit?
Ans : All of the above
Ques : Given the operators:
1) *
2) /
3) %
What would be the order of precedence?
Ans : 1 and 2 have the same precedence, 3 is of lower precedence
Ques : 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;
Ans : 1,2,3
Ques : What would be printed on the standard output as a result of the following code snippet?
main()
{
int n=5, x;
x = n++;
printf("%d ", x);
x = ++n;
printf("%d ", x++);
printf("%d", x);
return 0;
}
Ans : 5 7 8
Ques : In which area of memory are static variables allocated?
Ans : heap
Ques : Read the statement below:
extern int a;
Which of the following statement/s pertaining to the above statement is/are correct?
Ans : Brings the scope of the variable defined outside the file to this file
Ques : 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;
}
Ans : sdfgh
Ques : Which function returns the current pointer position within a file?
Ans : ftell()
Ques : Which of the following is a function for formatting data in memory?
Ans : sprintf()
Ques : Which function allocates memory and initializes elements to 0?
Ans : calloc()
Ques : 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} };
Ans : Yes, the size is three columns by two rows
Ques : Which of the following sets of conversion statements may result in the loss of data?
Ans : int i; float f; i=f; f=i;
Ques : Consider the following code.
int i = 4, *j, *k;
Which one of the following statements will result in Compilation error?
Ans : j = j * 2;
Ques : By which file function you can position the file pointer in accordance with the current position?
Ans : fseek()
Ques : What will be printed on the standard output as a result of the following code snippet?
void main()
{
int arr[][2] = {1,2,3,4,5,6};
printf("%d",arr[2][1]);
}
Ans : 6
Ques : Which function will you use to position the file pointer at the beginning of the file?
Ans : rewind()
Ques : Which header file are methods(or macros) isalpha(), islower() a part of?
Ans : ctype.h
Ques : 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);
}
Ans : 5 31 8
Ques : 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;
}
Ans : 0 1 6 7
Ques : What would be printed on the standard output as a result of the following code snippet?
main()
{
int a[5] = {1,4,5,6,9};
printf("%d\t", *a); //Line 1
printf("%d", *++a); //Line 2
return 0;
}
Ans : Compilation Error in "Line 2"
Ques : Which of the following standard functions is used to close a file?
Ans : fclose()
Ques : Identify the incorrect statement.
Ans : Memory is reserved when a structure label is defined
Ques : Which of the following comparison statements will be true if an integer is 16 bits and a long is 32 bits on a machine?
Ans : -1L > 1U
Ques : Which of the following is the correct way of initializing a two-dimensional array?
Ans : char str[2][4]={ {'a','b','c','\0'}, {'d','e','f','\0'} };
Ques : Which function will you use to write a formatted output to the file?
Ans : fprintf()
Ques : What would be printed on the standard output as a result of the following code snippet?
main()
{
char option = 5;
switch(option)
{
case '5':
printf("case : 1 \n");
break;
case 5:
printf("case : 2 \n");
break;
default:
printf("case : 3 \n");
break;
}
return 0;
}
Ans : case : 2
Ques : 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);
}
Ans : 4 3 5.99 4.50
Ques : What would be printed on the standard output as a result of the following code snippet?
main()
{
void addup (int b);
addup(b);
return 0;
}
int b = 5;
void addup (int b)
{
static int v1;
v1 = v1+b;
printf("%d ", v1);
}
Ans : Will result in Compilation Error
Ques : Given the following array declaration:
int a[2][3][4];
what would be the number of elements in array a?
Ans : 24
Ques : Which file header is to be included for file handling in a C program?
Ans : stdio.h
Ques : What is the return type of the following function declaration?
func(char c);
Ans : undefined
Ques : What is the function to concatenate two strings?
Ans : strcat()
Ques : Which of the following statements is valid and correct?
Ans : char amessage[] = "lmnop"; amessage++;
Ques : Which of the following is not a valid mode for opening a file?
Ans : i
Ques : 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]);?
Ans : m
Ques : What will be printed on the standard output as a result of the following code snippet?
void main()
{
char arr[] = {'R','A','M','\0'};
printf("%d",strlen(arr));
}
Ans : 3
Ques : Which function will convert a string into a double precision quantity?
Ans : atof()
Ques : Which of the following is not a type of operator ?
Ans : Ternary
Ques : The declaration int *(*p)[10] indicates:
Ans : p is a pointer to an array of integer pointers
Ques : 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;
}
Ans : 1 3 0 0
Ques : What would be printed on the standard output as a result of the following code snippet?
main( )
{
char *str[ ] = {
"Manish"
"Kumar"
"Choudhary"
};
printf ( "\nstring1 = %s", str[0] );
printf ( "\nstring2 = %s", str[1] );
printf ( "\nstring3 = %s", str[2] );
}
Ans : string1 = ManishKumarChoudhary string2 = (null) string3 = (null)
Ques : Which standard function is used to deallocate memory allocated by the malloc() function?
Ans : free
Ques : The declaration int (*p[5])() means:
Ans : p is an array of pointers to functions the return type of which is an integer
Ques :What will be printed on the standard output as a result of the following code snippet?
void main()
{
int arr[5]={1,2,3,4,5};
printf("%d\n", *(arr+4));
}
Ans : 5
Ques : What does the argv[0] represent?
Ans : The program name
Ques : What will happen when the following code is executed?
void main()
{
char arr1[] = "REGALINT";
char arr2[10] = "REGALINT";
printf("%d,",sizeof(arr1));
printf("%d",sizeof(arr2));
}
Ans : 9,10
Ques : What would be printed on the standard output as a result of the following code snippet?
main()
{
enum {red, green, blue = 0, white};
printf("%d %d %d %d", red, green, blue, white);
return 0;
}
Ans : 0 1 0 1
Ques : What is wrong with the following function prototype statement?
int func();
Ans : While calling a function, the type int is not needed
Ques : 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));
}
Ans : Cannot be determined
Ques : Which of the following is not a storage type?
Ans : auto
Ques :If a two dimensional array arr[4][10](an array with 4 rows and 10 columns) is to be passed in a function, which of the following would be the valid parameters in the function definition?
Ans : fn(int arr[4][10])
Ques : Which of the following is not a string function?
Ans : strcomp()
Ques : 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);
Ans : a
Ques : What will be printed on the standard output as a result of the following code snippet?
void main()
{
char arr1[] = "REGALINT";
printf("%d,",strlen(arr1));
printf("%d",sizeof(arr1));
}
Ans : 8,9
Ques : What will be printed on the standard output as a result of the following code snippet?
int funr(int x, int y)
{
if(x <= 0)
{
return y;
}
else
{
return (1+funr(x-1,y));
}
}
void main()
{
printf("%d",funr(2,3));
}
Ans : 5
Ques : What would be printed on the standard output as a result of the following code snippet?
#define Name Manish
main()
{
printf("My name""Name");
}
Ans : My nameName
Ques : What will be printed on the standard output as a result of the following code snippet?
main()
{
int num = 425;
printf("%d", printf("%d", num));
}
Ans : 4253
Ques : What would be printed on the standard output as a result of the following code snippet?
main()
{
signed char i = 1;
for (; i<=255; i++)
printf ("%d ",i);
return 0;
}
Ans : 1 2 3 . . . 127 -128 -127 ... 0 1 2 3 . . . (infinite times)
Ques : 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));
}
Ans : 4.50
Ques : Which of the following is not a file related function?
Ans : puts()
Ques : 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, c = 5;
printf("%d ", max(a++, c++));
printf("%d %d\n", a,c);
}
Ans : 6 5 7
Ques : Which of the following file modes would mean read + append?
Ans : a+
Ques : What would be printed on the standard output as a result of the following code snippet?
int Recur(int num)
{
if(num==1 || num==0)
return 1;
if(num%2==0)
return Recur(num/2)+2;
else
return Recur(num-1)+3;
}
int main()
{
int a=9;
printf("%d\n", Recur(a));
return 0;
}
Ans : 10
Ques : What will happen when the following code is executed?
{
int num;
num =0;
do {-- num;
printf("%d\n", num);
num++;
} while (num >=0);
}
Ans : The loop will run infinitely
Ques : Which of the following functions is used to extract formatted input from a file?
Ans : fscanf()
Ques : What does the following function do?
int fn(unsigned int x)
{
int count = 0;
for(; x!=0; x&=(x-1))
count++;
return count;
}
Ans : Returns the number of 1 bits(bits having one) in the number x
Thanks for watching this test Question & Answers. Please don't forget to leave a comment about this post. You can also find some more effective test question & answers, information, techniques, technology news, tutorials, online earning information, recent news, results, job news, job exam results, admission details & another related services on the following sites below. Happy Working!
News For Todays UpWork Elance Tests oEtab ARSBD-JOBS DesignerTab
UpWork (oDesk) & Elance C Programming Test Question & Answers
Reviewed by ARSBD
on
July 04, 2015
Rating: