Here, We see C (Programming Language) LinkedIn Skill Assessment Answer. This assessment test consists of 15-20 MCQs to demonstrate your knowledge of your selected skills. MCQs come from different topics – Control Flow and Operators, Functions, I/O and File I/O, Memory Management, Storage, Concurrency, Program Basics, and Data Structures.

## C (Programming Language) Tutorial ->

### Q1. Which Code sample will eventually cause the computer to run out of memory?

1. A✔️
``````while(1)
{
char *smallString = (char *) malloc(10);
}
``````
1. B
``````long long number = 1;
while(1)
number *= 2;
``````
1. C
``````while(1)
{
char hugeString[1000000L];
memset(hugeString, 0, 1000000L);
}
``````
1. D
``````while(1)
{
long *bigArray = (long *) malloc(sizeof(long) * 1000);
memset(bigArray, 1000000, 1000);
free(bigArray);
}
``````

## Q2. What will this code print on the screen?

``````int f1 (int a, int b)
{
if (a > b)
{
printf("A is greater than B\n");
return 1;
}
else
{
printf("B is greater than A");
return 0;
}
}

main()
{
if (f1(20,10) || f1(10,20))
printf("C is fun!\n");
}
``````
1. A✔️
``````A is greater then B
C is fun!
``````
1. B
``````A is greater then B
B is greater then A
C is fun!
``````
1. C
``````A is greater then B
B is greater then A
``````
1. Nothing is printed on Screen

## Q3. What is the name for calling a function inside the same function?

1. recursion✔️
2. subfunction
3. inner call
4. infinite loop

## Q4. What does the declaration of variable c2 demonstrate?

``````main(){
char c1 ='a';
char c2 = c1+10;
}
``````
1. character arithmetic✔️
2. undefined assignment
3. type conversion
4. invalid declaration

## Q5. A pointer to void named vptr, has been set to point to a floating point variable named g. What is the valid way to dereference vptr to assign its pointed value to a float variable named f later in this program?

``````float g;
void *vptr=&g;
``````
1. f = _(float _)vptr;
2. f = (float *)vptr;
3. f = *(float *)vptr;✔️
4. f = *(float)vptr;

## Q6. What is this declaration an example of?

``````struct s {
int i;
struct s *s1;
struct s *s2;
};
``````
1. a node✔️
3. a stack
4. a binary tree

## Q7. A C header file is a file with extension .h that contains function declarations and macro definitons to be shared between several source files. Header files are listed using the preprocessing directive #include, and can have one of the following formats: #include <fileA> or #include "fileB". What is the difference between these two formats?

1. The preprocessor will try to locate the fileA in same directory as the source file, and the fileB in a predetermined directory path.
2. The preprocessor will try to locate the fileA in the fixed system directory. It will try to locate fileB in the directory path designated by the -l option added to the command line while compiling the source code.
3. The file using fileA syntax must be system files, of unlimited number. fileB must be a user file at a maximun of one per source file.
4. The preprocessor will try to locate the fileA in a predetermined directory path. It will try to locate fileB in the same directory as the source file along with a custom directory path.✔️

## Q8. Using a for loop, how could you write a C code to count down from 10 to 1 and display each number on its own line?

1. A
``````for (int i = 0; i>=0, i--){
printf("%d\n", i);
}//end of loop
``````
1. B
``````int i;
for (i=1; i<=10; i++){
printf("%d", i);
}
``````
1. C
``````int i = 10;
while (i>0){
printf("%d\n", i);
i--;
}
``````
1. D✔️
``````int i;
for (i= 10; i>0; i--){
printf("%d\n", i);
}// end of loop
``````

1. volatile
2. typeof✔️
3. register
4. typedef

## Q10. What does the program shown below return?

``````int main(){
int a=1, b=2, c=3, d=4;
int x = a;
if (a>b)
if (b<c) x=b;
else x=c;
return(x);
}
``````
1. 1✔️
2. 3
3. 2
4. 0

## Q11. Using the Union declaration below, how many bytes of memory space will the data of this type occupy?

``````union Cars {
char make;
char model;
short year;
} car;
``````
1. 32
2. 54
3. 30✔️
4. 52

## Q12. In this code sample, what is not a problem for C compiler?

``````main(){
constant int PI = 3.14;
printf("%f\n", pi);
}
``````
1. The value of PI needs to be set to 3.141593, not 3.14✔️
2. The declaration of PI needs to say const, not constant.
3. The data type of PI needs to be float not int.
4. The printf statement needs to use PI, not pi.

## Q13. Which is the smallest program to compile and run without errors?

1. main()
2. int main() {return 0;}✔️
3. main() { }
4. main() { ; }

## Q14. What is optional in a function declaration?

1. data type of parameters
2. return type of function
3. parameter names✔️
4. number of parameters

1. stdout✔️
2. stdio.h
3. default.h
4. string.h

## Q16. In which segment does dynamic memory allocation takes place?

1. BSS Segment
2. stack
3. heap✔️
4. data segment

1. dalloc()
2. dealloc()
3. release()
4. free()✔️

1. keywords
2. identifiers
3. tokens✔️
4. functions

## Q19. When is memory for a variable allocated?

1. during the assigment of the variable
2. during the initialization of the variable
3. during the declaration of the variable✔️
4. during the definition of the variable

## Q20. By default c uses the call by value method to pass arguments to functions. How can you invoke the call by reference method?

1. by using pointers✔️
2. by declaring functions separately from defining them
3. by using recursive functions
4. by using global variables

## Q21. A union allows you to store different ___ in the same ___.

1. Objects; Structure
2. Variables; Declaration
3. Data types; Memory location✔️

## Q22. What is the output of this program?

``````main() {
char c1='a' , c2='A';
int i=c2-c1;
printf("%d", i);
}
``````
1. 32
2. Runtime error
3. -32✔️
4. 0

## Q23. What is the difference between scanf() and sscanf() functions?

1. The scanf() function reads data formatted as a string; The sscanf() function reads string input from the screen.
2. The scanf() function reads formatted data from the keyboard; The sscanf() function reads formatted input from a string.✔️
3. The scanf() function reads string data from the keyboard; The sscanf() function reads string data from a string.
4. The scanf() function reads formatted data from a file; The sscanf() function reads input from a selected string

## Q24. What is not a valid command with this declaration?

### char *string = { "one", "two", "three"};

1. printf("%c", string);
2. printf("%s", string);✔️
3. printf("%s", string);
4. printf(string);

## Q25. What is the expression player->name equivalent to?

1. player.name
2. (*player).name✔️
3. *player.name
4. player.*name

## Q26. Which program will compile and run without errors?

1. A
``````main() {
for(i=0; i<10; i++) ;
}
``````
1. B✔️
``````main() {
int i=0;
for(; i<10; i++) ;
}
``````
1. C
``````main() {
int i;
for(i=0; i<j; i++) ;
}
``````
1. D
``````main() {
int i;
for (i= 10; i<10; i++)
}
``````

## Q27. What does this function call return?

``````1 main() { float x = f1(10, 5); }
2 float f1(int a, int b) { return (a/b); }
``````
1. 2
2. 2.000000
3. a runtime error
4. a compiler error✔️

## Q28. What does this program create?

``````#include <stdio.h>
int main() {
int *p = NULL;
return 0;
}
``````
1. a runtime error
2. a NULL pointer✔️
3. a compile error
4. a void pointer

## Q29. What is an alternative way to write the expression (*x).y?

1. There is no equivalent.
2. x->y✔️
3. *x->y
4. y->x

## Q30. Compile time errors are static errors that can be found where in the code?

1. in declarations and definitions✔️
2. in functions and expressions
3. in syntax and semantics
4. in objects and statements

1. in Unix✔️
2. in C++
3. in C#
4. in DOS

## Q32. What does the strcmp(str1, str2); function return?

1. 0 if str1 and str2 are the same, a negative number if str1 is less than str2, a positive number if str1 is greater than str2✔️
2. true (1) if str1 and str2 are the same, false (0) if str1 and str2 are not the same
3. true (1) if str1 and str2 are the same, NULL if str1 and str2 are not the same
4. 0 if str1 and str2 are the same, a negative number if str2 is less than str1, a positive number if str2 is greater than str1

## Q33. What is the output of this program?

``````int a=10, b=20;
int f1(a) { return(a*b); }
main() {
printf("%d", f1(5));
}
``````
1. 100✔️
2. 200
3. 5
4. 50

## Q34. Which is not a correct way to declare a string variable?

1. char *string = "Hello World";
2. char string = "Hello World";✔️
3. char string = {‘H’, ‘e’, ‘l’, ‘l’, ‘o’, ‘ ‘, ‘W’, ‘o’, ‘r’, ‘l’, ‘d’};
4. char string[] = "Hello World";

## Q35. Which choice is an include guard for the header file mylib.h?

1. A
``````#ifdef MYLIB_H
#undef MYLIB_H

// mylib.h content

#endif /* MYLIB_H */
``````
1. B✔️
``````#ifndef MYLIB_H
#define MYLIB_H

// mylib.h content

#endif /* MYLIB_H */
``````
1. C
``````#define MYLIB_H
#include "mylib.h"

#undef MYLIB_H
``````
1. D
``````#ifdef MYLIB_H
#define MYLIB_H

// mylib.h content

#endif /* MYLIB_H */
``````

## Q36. How many times does the code inside the while loop get executed in this program?

``````main(){
int x=1;
while(x++<100){
x*=x;
if(x<10) continue;
if(x>50) break
}
}
``````
1. 100
2. 3✔️
3. 5
4. 50

## Q37. File input and output (I/O) in C is done through what?

1. syntax-driven components
2. native interfaces
3. system objects
4. function calls✔️

## Q38. Directives are translated by the?

1. Pre-processor✔️
2. Compiler
4. Editor

1. global
2. static
3. library✔️
4. system

## Q40. You have written a function that you want to include as a member of structure a. How is such as structure member defined?

1. A✔️
``````struct a {
void *f1;
};
``````
1. B
``````struct a {
void (*f1)();
};
``````
1. C
``````struct a {
*(void *f1)();
};
``````
1. D
``````struct a {
void *f1();
};
``````

1. FIFO
2. LIFO✔️
3. LILO
4. LOLI

## Q42. What does this program display?

``````main(){
char *p = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
int i;
for (i=0;i<5;i++) *p++; *p++;
printf("%c",*p++);
}
``````
1. K
2. M
3. H
4. G✔️

## Q43. Describe the relationship between lvalue and rvalue.

1. An lvalue may appear only on the left-hand side of an assignment; an rvalue may appear only on the right-hand side.
2. An lvalue may appear only on the left-hand side of an assignment; an rvalue may appear on either the left-hand or right-hand side.
3. An lvalue and an rvalue may appear on either left-hand or right-hand side of an assignment.
4. An lvalue may appear on the left-hand or right-hand side of an assignment; an rvalue may appear only on the right-hand side.✔️

1. %
2. **
3. ‘*’
4. &✔️

## Q45. Which add function properly returns the updated value of result?

1. A✔️
``````void add (int a, int b, int *result)
{
*result = a+b;
}

main()
{
int a = 10;
int b = 20;
int result = 0;

}
``````
1. B
``````void add (int a, int b, int result)
{
result = a+b;
}

main()
{
int a = 10;
int b = 20;
int result = 0;

}
``````
1. C
``````void add (int a, int b, int *result)
{
result = a+b;
}

main()
{
int a = 10;
int b = 20;
int result = 0;

}
``````
1. D
``````void add (int *a, int *b, int *result)
{
result = a+b;
}

main()
{
int a = 10;
int b = 20;
int result = 0;

}
``````

## Q46. Consider the number of the Fibonacci series below 100: 0,1,1,2,3,5,8,13,21,34,55,89. Which piece of code outputs the sequence?

1. A
``````void fibonacci(int a, int b)
{
int c = a+b;

if(a>100)
return;

printf("%d", a);

fibonacci(a,b);
}

int main()
{
fibonacci(0,1);
}
``````
1. B
``````void fibonacci(int a, int b)
{
int c = a+b;

if(a>100)
return;

printf("%d", b);

fibonacci(a,c);
}

int main()
{
fibonacci(0,1);
}
``````
1. C✔️
``````void fibonacci(int a, int b)
{
int c = a+b;

if(a>100)
return;

printf("%d", a);

fibonacci(b,c);
}

int main()
{
fibonacci(0,1);
}
``````
1. D
``````void fibonacci(int a, int b)
{
int c = a+b;

if(a>100)
return;

printf("%d", c);

fibonacci(b,c);
}

int main()
{
fibonacci(0,1);
}
``````

1. intern✔️
2. extern
3. register
4. static

Reference

## Q48. Which line of code, after execution, results in i having the value of 1?

1. for(i=1; i<=1; i++);
2. for(i=1; i=10; i++);
3. for(i=1; i==10; i++);✔️
4. for(i=10; i>=1; i–);

## Q49. What is the value of variable c at the end of this program?

``````1 main() {
2   int a, b, c;
3   a=10; b=50;
4   c=a * b % a;
5 }
``````
1. 50
2. 5
3. 0✔️
4. 500

## Q50. What is not one of the basic data types in C

1. long double
2. unsigned char
3. array✔️
4. float

1. ,
2. []
3. .✔️
4. :

1. char✔️
2. float
3. int
4. short

## Q53. what does the ctype tolower() function do?

1. It returns TRUE for lowercase letters of the alphabet.
2. It ensures that text output uses only ASCII values (0 through 127).
3. It returns FALSE for lowercase letters of the alphabet.
4. It converts an uppercase letter of the alphabet to lowercase.✔️

## Q54. Void pointer vptr is assigned the address of float variable g. What is a valid way to dereference vptr to assign its pointed value to a float variable named f later in the program?

``````float g;
void *vptr=&g;
``````
1. f=(float *)vptr;
2. *f=*(float )vptr;✔️
3. f=*(float)vptr;
4. f=(float)*vptr;

1. stdio.h
2. stdlib.h✔️
3. limits.h
4. stddef.h

## Q56. A function is a set of __.

1. declarations
2. statements✔️
3. variables
4. objects

## Q57. How are static functions different from global functions?

1. Static functions must be declared in advance of being defined.
2. Static functions must be declared is a separate header file.
3. Static functions always return the same value.
4. Static functions can be accessed only in the file where they are declared.✔️

## Q58. Which code example creates the string "Hello Mars" in storage buffer hello.

1. A
``````    char hello;
strcpy(hello, "Hello ");
strcpy(hello, "Mars");
``````
1. B✔️
``````    char hello;
char *p;
strcpy(hello, "Hello World");
p = hello;
p +=6;
strcpy(p, "Mars");
``````
1. C
``````    char *hello;
strcpy(hello, "Hello World");
hello+=6;
strcpy(hello, "Mars");
``````
1. D
``````    char hello;
strcpy(hello, "Hello World");
strcpy(*hello, "Mars");
``````

## Q59. If you use the fopen() function with the "a" mode, what happens if the named file doesn’t exist?

1. The file is created and opened for reading.
2. The file is created and opened for writing.✔️
3. The fopen() function returns a NULL indicating that the operation has failed.
4. The file is created and opened for both writing and reading

## Q60. What does this function return?

### int fl(int a, int b) { return(a>b?a:b); }

1. compiler error
2. the smaller value of the two passed parameters
3. runtime error
4. the greater value of the two passed parameters✔️

## Q61. Which option is a valid function name?

1. draw_star()✔️
2. 5times()
3. upper-limit()
4. auto()

## Q62. What is not a valid type definition of a structure that contains x and y coordinates as integers, and that can be used as shown for the variable named point?

``````coord point;
point.x = 9;
point.y = 3;
``````
1. A
``````struct coord{
int x;
int y;
};
typedef struct coord coord;
``````
1. B✔️
``````typedef struct coord{
int x;
int y;
};
``````
1. C
``````typedef struct coord{
int x;
int y;
} coord;
``````
1. D
``````typedef struct{
int x;
int y;
} coord;
``````

## Q63. What is the output of the below program?

``````#include <stdio.h>
#if X == 3
#define Y 3
#else
#define Y 5
#endif

int main()
{
printf("%d", Y);
return 0;
}
``````
1. 3
2. 5✔️
3. 3 or 5 depending on input
4. Compile time error

## Q64. What do the functions malloc() and calloc() allocate?

1. reallocatged memory
2. static memeory
3. dynamic memory✔️
4. fragmented memory

## Q65. You need to determine if a string variable is a substring of another string. Which standard C library function do you use?

1. substr(str1, str2);
2. strstr(str1, str2);✔️
3. substring(str1, str2);
4. strspn(str1, str2);

## Q66. Find the output of the program?

``````#include <stdio.h>

#define L 10
int main(){
int a =10;
switch (a,a<<2){
case L:printf("a==L");     break;
case L*2 : printf("a = L* 2\n");     break;
case L*4 : printf("a = L* 4\n");    break;
default: printf("Error\n");
}
}
``````
1. a=L*2
2. a=L
3. Error
4. a=L*4✔️

## Q67. Predict the output of the following code when the interger variables x is initialized to 10,y to 2 and z to 0.

``````z = x + y * x + 10 / 2 * x;
printf("value is =%d",z);
``````
1. 80✔️
2. 170
3. 31.5
4. 6

## Q68. What will be the output of the following code snippet?

``````#include <stdio.h>
void solve() {
int x = 2;
printf("%d", (x << 1) + (x >> 1));
}
int main() {
solve();
return 0;
}
``````
1. 5✔️
2. 4
3. 2
4. 1

## Q69. What is the output of this program?

``````int a=20, b=10;
int f1(a) {
return(a*b);
}
main() {
printf("%d", f1(5));
}
``````
1. 100
2. 200
3. 5
4. 50✔️

## Q70. What is /0 character ?

1. String
2. NULL Character✔️
3. ZERO
4. Variable

## Q71. What is correct output for follwing code?

``````#include&lt;stdio.h&gt;
#include&lt;conio.h&gt;
main()
{
int a=10, b=20;
clrscr();
printf("Before swapping a=%d b=%d",a,b);
a=a+b;
b=a-b;
a=a-b;
printf("nAfter swapping a=%d b=%d",a,b);
getch();
}
``````
1. Before a=10 b=20 , After a=10 b=10
2. Before a=10 b=10 , After a=20 b=10
3. Before a=10 b=20 , After a=20 b=20
4. Before a=10 b=20 , After a=20 b=10✔️

## Q72. What is Incorrect option that explain # pragma directive ?

1. #pragma exit allows us to specify functions called upon program exit.
2. This is a preprocessor directive that can be used to turn on or off certain features.
3. #pragma startup don’t allows us to specify functions called upon program startup.✔️
4. It is of two types #pragma startup, #pragma exit and pragma warn.

## Q73. What will be the output of the following code snippet?

``````#include <stdio.h>
union School {
int age, rollNo;
double marks;
};
void solve() {
union School sc;
sc.age = 19;
sc.rollNo = 82;
sc.marks = 19.04;
printf("%d", (int)sizeof(sc));
}
int main() {
solve();
return 0;
}
``````
1. 2
2. 4
3. 8✔️
4. 10

## Q74. What will be the output of the following code snippet?

``````#include <stdio.h>
struct School {
int age, rollNo;
};
void solve() {
struct School sc;
sc.age = 19;
sc.rollNo = 82;
printf("%d %d", sc.age, sc.rollNo);
}
int main() {
solve();
return 0;
}
``````
1. 19 82✔️
2. Compilation Error
3. 82 19
4. None of these

## Q75. What is the output of the following code snippet?

``````int main() {
int sum = 2 + 4 / 2 + 6 * 2;
printf("%d", sum);
return 0;
}
``````
1. 2
2. 15
3. 16✔️
4. 18

## Q76. What does the following declaration mean?

### int (*ptr);

1. ptr is array of pointers to 10 integers
2. ptr is a pointer to an array of 10 integers✔️
3. ptr is an array of 10 integers
4. ptr is an pointer to array

## Q77. What will be the output of the following code snippet?

``````#include <stdio.h>
void change(int,int);
int main()
{
int a=10,b=20;
change(a,b); //calling a function by passing the values of variables.
printf("Value of a is: %d",a);
printf("\n");
printf("Value of b is: %d",b);
return 0;
}
void change(int x,int y)
{
x=13;
y=17;
}
``````
1. 10,20✔️
2. 10,10
3. 20,20
4. 20,10

1. True✔️
2. False

## Q79. What does the following fragment of C-program print?

``````#include <stdio.h>

int main()
{
char c[] = "GATE2011";

char *p = c;

printf("%s", p + p -p);

return 0;
}
``````
1. GATE 2011
2. E2011
3. 2011✔️
4. 01

## Q80. What is the output of the following code snippet?

``````int main() {
int a = 5, b = 6, c;
c = a++ + ++b;
printf("%d %d %d", a, b, c);
return 0;
}
``````
1. 5 6 11
2. 6 7 12✔️
3. 5 6 12
4. 6 6 12

## Q81. What will be the output of the following C program segment?

``````char inchar = 'A';
switch (inchar)
{
case 'A' :
printf ("choice A \n") ;
case 'B' :
printf ("choice B ") ;
case 'C' :
case 'D' :
case 'E' :
default:
printf ("No Choice") ;
}

``````
1. No choice
2. Choice A
3. Choice A Choice B No choice✔️
4. Program gives no output as it is erroneous

## Q82. Which of the following is the correct syntax to print the message in C++ language?

1. Out <<"Hello world!
2. Cout << Hello world! ;
3. cout <<"Hello world!";✔️
4. None of the above

## Q83. String variable str1 has the value of "abc", and string variable str2 has the value "xyz". What are the values of str1 and str2 after this statement is executed?

### strcpy(str1, str2);

1. str1: "xyz" ; str2: "xyz"✔️
2. str1: "abc" ; str2: "xyz"
3. str1: "xyz" ; str2: "abc"
4. str1: "abc" ; str2: "abc"

## Q84. The main loop structures in C programming are the for loop, the while loop, and which other loop?

1. do…while✔️
2. for…in
3. repeat…until
4. do…until

IT Operations Quiz MCQs come from different topics – IT Operations like Internal Components, Internet,…

BASH Quiz MCQs come from different topics – Bash Operators, Scripting, Expansion, Environment, and…

VBA Quiz MCQs come from different topics – Declarations, Procedures, and Calls, Syntax, User-Defined Elements,…