You are on page 1of 14

My Profile Home Log Out

Welcome Partha Garai (impersonating Nasrin Sultana Khatun) JECA Mock8 (C + OOPS + UNIX)
Logged in as Student
Thursday 22nd Jun, 2023 04:15:45 PM

Search Student
Section : J-1st_Sem 2022 Course : JECA Joint Entrance Exam MCA (WB JECA)
Academics and Personal Info
Year : 2022-2023 Full Marks : 120
View Attendance

View Marks Group A (C Programming): Answer All question(s)


1. What is the use of getchar()? Marks: 1 (Correct: c)
Submit Assignments
c) The next input character each time it is called EOF
a) The next input character each time it is called b) EOF when it encounters end of file d) None of the mentioned
when it encounters end of file
Knowledge Assessment
Explanation: None.
View Books
2. If the file name is enclosed in angle brackets, then ___________ Marks: 1 (Correct: b)
View Timetable
c) The preprocessor treats it as a user-defined file
a) The preprocessor treats it as a user-defined file b) The preprocessor treats it as a system-defined file d) None of the mentioned
and system-defined file
Download Class Materials
Explanation: None.
View Previous Questions 3. Automatic variables are allocated space in the form of a __________ Marks: 1 (Correct: a)

Submit Course Feedbacks a) stack b) queue c) priority queue d) random

Explanation: None.

4. What will be the output of the following C code? Marks: 1 (Correct: c)

#include

int main()

printf("sanfoundry

class

");

return 0;

b)

a) sanfoundryclass sanfoundry c) classundry d) sanfoundry


class

Explanation: r is carriage return and moves the cursor back. sanfo is replaced by class. Output: $ cc pgm8.c $ a.out classundry

5. Which of the following technique is faster for travelling in binary trees? Marks: 1 (Correct: b)

a) Iteration b) Recursion c) Both Iteration and Recursion d) Depends from compiler to compiler

Explanation: None.
This Site Maintained by Webtech Services
6. Which of the following data type will throw an error on modulus operation(%)? Marks: 1 (Correct: d)

a) char b) short c) int d) float

Explanation: None.

7. What will be the output of the following C code? Marks: 1 (Correct: a)

#include

void main()

int k = 4;

float k = 4;

printf("%d", k)

a) Compile time error b) 4 c) 4.0000000 d) 4.4

Explanation: Since the variable k is defined both as integer and as float, it results in an error. Output: $ cc pgm8.c pgm8.c: In function ‘main’: pgm8.c:5: error: conflicting types for ‘k’ pgm8.c:4: note: previous definition of ‘k’ was here pgm8.c:6: warning: format ‘%d’
expects type ‘int’, but argument 2 has type ‘double’ pgm8.c:7: error: expected ‘;’ before ‘}’ token

8. What linkage does automatic variables have? Marks: 1 (Correct: c)


a) Internal linkage b) External linkage c) No linkage d) None of the mentioned

Explanation: None.

9. What is #include ? Marks: 1 (Correct: a)


a) Preprocessor directive b) Inclusion directive c) File inclusion directive d) None of the mentioned

Explanation: None.

10. What will be the output of the following C code? Marks: 1 (Correct: a)

#include

void func();

int main()

static int b = 20;

func();

}
This Site Maintained by Webtech Services
void func()

static int b;

printf("%d", b);

d) Compile time error due to redeclaration of static


a) Output will be 0 b) Output will be 20 c) Output will be a garbage value
variable

Explanation: None.

11. What is the scope of an automatic variable? Marks: 1 (Correct: c)


c) Exist only within that scope in which it is declared and
a) Exist only within that scope in which it is declared b) Cease to exist after the block is exited d) All of the mentioned
exist after the block is exited

Explanation: None.

12. What will be the output of the following C code? Marks: 1 (Correct: a)

#include

int main()

int a = 10;

double b = 5.6;

int c;

c = a + b;

printf("%d", c);

a) 15 b) 16 c) 15.6 d) 10

Explanation: None.

13. The #elif directive cannot appear after the preprocessor #else directive. Marks: 1 (Correct: a)

a) TRUE b) FALSE c) d)

Explanation: None.
This Site Maintained by Webtech Services
14. What will be the output of the following C code? Marks: 1 (Correct: b)

#include

int main()

int i = 3;

int l = i / -2;

int k = i % -2;

printf("%d %d

", l, k);

return 0;

a) Compile time error b) -1 1 c) 1 -1 d) Implementation defined

Explanation: None

15. What is the syntax for constant pointer to address (i.e., fixed pointer address)? Marks: 1 (Correct: b)
a) const <type> * <name> b) <type> * const <name> c) <type> const * <name> d) none of the mentioned

Explanation: None.

16. What will be the output of the following C code? Marks: 1 (Correct: b)

#include

int main()

int i = 5;

i = i / 3;

printf("%d

", i);

return 0;
This Site Maintained by Webtech Services
}

a) Implementation defined b) 1 c) 3 d) Compile time error

Explanation: None

17. C99 standard guarantees uniqueness of ___________ characters for external names. Marks: 1 (Correct: a)
a) 31 b) 6 c) 12 d) 14

Explanation: ISO C99 compiler may consider only first 31 characters for external names.

18. What will be the output of the following C code? Marks: 1 (Correct: d)

#include

int main()

int a[5] = {1, 2, 3, 4, 5};

int i;

for (i = 0; i < 5; i++)

if ((char)a[i] == '5')

printf("%d

", a[i]);

else

printf("FAIL

");

a) The compiler will flag an error b) The program will compile and print the output 5 c) The program will compile and print the ASCII value of 5 d) The program will compile and print FAIL for 5 times

Explanation: The ASCII value of 5 is 53, the char type-casted integral value 5 is 5 only. Output: $ cc pgm1.c $ a.out FAIL FAIL FAIL FAIL FAIL

19. Which of the following function declaration is illegal? Marks: 1 (Correct: d)


a) int 1bhk(int); b) int 1bhk(int a); c) int 2bhk(int*, int []); d) all of the mentioned

Explanation: None.

20. Which keyword is used to come out of a loop only for that iteration? Marks: 1 (Correct: b)

a) break b) continue c) return d) none of the mentioned

Explanation: None.
This Site Maintained by Webtech Services
21. Relational operators cannot be used on ____________ Marks: 1 (Correct: a)
a) structure b) long c) strings d) float

Explanation: None.

22. Calling a function f with a an array variable a[3] where a is an array, is equivalent to __________ Marks: 1 (Correct: d)
a) f(a[3]) b) f(*(a + 3)) c) f(3[a]) d) all of the mentioned

Explanation: None.

23. C preprocessors can have compiler specific features. Marks: 1 (Correct: a)

a) TRUE b) FALSE c) Depends on the standard d) Depends on the platform

Explanation: #pragma is compiler specific feature.

24. Which of the following arithmetic operation can be applied to pointers a and b? Marks: 1 (Correct: b)
(Assuming initialization as int *a = (int *)2; int *b = (int *)3;)

a) a + b b) a - b c) a * b d) a / b

Explanation: None.

25. Presence of code like "s.t.b = 10" indicates __________ Marks: 1 (Correct: b)
a) Syntax Error b) Structure c) double data type d) An ordinary variable name

Explanation: None.

26. What will be the output of the following C code? Marks: 1 (Correct: d)

#include

void main()

int x = 5.3 % 2;

printf("Value of x is %d", x);

a) Value of x is 2.3 b) Value of x is 1 c) Value of x is 0.3 d) Compile time error

Explanation: None

27. What will be the output of the following C code? Marks: 2 (Correct: c)

#include

#define a 10

int main()

const int a = 5;

This Site Maintained by Webtech Services


printf("a = %d

", a);

a) a = 5 b) a = 10 c) Compilation error d) Runtime error

Explanation: The #define substitutes a with 10 without leaving any identifier, which results in Compilation error. Output: $ cc pgm3.c pgm3.c: In function ‘main’: pgm3.c:5: error: expected identifier or ‘(’ before numeric constant

28. Which of the following declaration is not supported by C? Marks: 1 (Correct: a)


a) String str; b) char *str; c) float str = 3e2; d) Both “String str;” and “float str = 3e2;”

Explanation: It is legal in Java, but not in C.

29. Automatic variables are allocated memory in ___________ Marks: 1 (Correct: d)


a) heap b) Data segment c) Code segment d) stack

Explanation: None.

30. Is initialisation mandatory for local static variables? Marks: 1 (Correct: b)


a) Yes b) No c) Depends on the compiler d) Depends on the standard

Explanation: None.

31. For a typical program, the input is taken using _________ Marks: 1 (Correct: d)
a) scanf b) Files c) Command-line d) All of the mentioned

Explanation: None.

32. Which of the following are C preprocessors? Marks: 1 (Correct: d)


a) #ifdef b) #define c) #endif d) all of the mentioned

Explanation: None.

33. In the following code snippet, character pointer str holds a reference to the string ___________ Marks: 2 (Correct: b)

char *str = "Sanfoundry.com" "training classes";

a) Sanfoundry.com b) Sanfoundry.comtraining classes c) Sanfoundry.comtraining classes d) Invalid declaration

Explanation: ‘’ is accepted as a char in the string. Even though strlen will give length of string “Sanfoundry.com”, in memory str is pointing to entire string including training classes.

34. What is the precedence of arithmetic operators (from highest to lowest)? Marks: 1 (Correct: a)

a) %, *, /, +, – b) %, +, /, *, – c) +, -, %, *, / d) %, +, -, *, /

Explanation: None

35. Which type of variables can have the same name in a different function? Marks: 1 (Correct: d)

a) Global variables b) Static variables c) Function arguments d) Both static variables and Function arguments

Explanation: None.

36. What will be the output of the following C statement? (assuming the input is “cool brother in city”) Marks: 1 (Correct: a)

printf(“%s

”, argv[argc]);

a) (null) b) City c) In d) Segmentation Fault

Explanation: None.

37. What is short int in C programming? Marks: 1 (Correct: c)

a) The basic data type of C b) Qualifier c) Short is the qualifier and int is the basic data type d) All of the mentioned

Explanation: None.

38. Which of the following cannot be a structure member? Marks: 1 (Correct: b)

a) Another structure b) Function c) Array d) None of the mentioned

This Site Maintained by Webtech Services


Explanation: None.

39. What will be the final value of x in the following C code? Marks: 1 (Correct: c)

#include

void main()

int x = 5 * 9 / 3 + 9;

a) 3.75 b) Depends on compiler c) 24 d) 3

Explanation: None

40. Which among the following is NOT a logical or relational operator? Marks: 1 (Correct: d)

a) != b) == c) || d) =

Explanation: None.

Group B (OOPS): Answer All question(s)


41. Which among the following is wrong? Marks: 1 (Correct: b)
d) abstract class student{ }; class toppers: public student{
a) class student{ }; student s; b) abstract class student{ }; student s; c) abstract class student{ }s[50000000];
}; topper t;

Explanation: We can never create instance of an abstract class. Abstract classes doesn’t have constructors and hence when an instance is created there is no facility to initialize its members. Option d is correct because topper class is inheriting the base abstract
class student, and hence topper class object can be created easily.

42. Which among the following can be viewed as combination of abstraction of data and code. Marks: 1 (Correct: b)
a) Class b) Object c) Inheritance d) Interfaces

Explanation: Object can be viewed as abstraction of data and code. It uses data members and their functioning as data abstraction. Code abstraction as use of object of inbuilt class.

43. Which feature in OOP is used to allocate additional function to a predefined operator in any language? Marks: 1 (Correct: a)
a) Operator Overloading b) Function Overloading c) Operator Overriding d) Function Overriding

Explanation: The feature is operator overloading. There is not a feature named operator overriding specifically. Function overloading and overriding doesn’t give addition function to any operator.

44. Which among the following can be used together in a single class? Marks: 1 (Correct: d)
a) Only private b) Private and Protected together c) Private and Public together d) All three together

Explanation: All the classes can use any of the specifiers as needed. There is no restriction on how many of them can be used together.

45. When an object is returned___________ Marks: 1 (Correct: a)


b) The same object used in function is used to return the c) The Object can be returned without creation of d) Object are returned implicitly, we can’t say how it
a) A temporary object is created to return the value
value temporary object happens inside program

Explanation: A temporary object is created to return the value. It is created because the object used in function is destroyed as soon as the function is returned. The temporary variable returns the value and then gets destroyed.

46. Which constructor is called while assigning some object with another? Marks: 1 (Correct: c)
a) Default b) Parameterized c) Copy d) Direct assignment is used

Explanation: Copy constructor is used while an object is assigned with another. This is mandatory since we can’t decide which member should be assigned to which member value. By using copy constructor, we can assign the values in required form.

47. Which header file is required in C++ to use OOP? Marks: 1 (Correct: d)
a) iostream.h b) stdio.h c) stdlib.h d) OOP can be used without using any header file

Explanation: We need not include any specific header file to use OOP concept in C++, only specific functions used in code need their respective header files to be included or classes should be defined if needed.

48. If constructors of a class are defined in private access, then __________ Marks: 1 (Correct: a)
a) The class can’t be inherited b) The class can be inherited c) Instance can be created only in another class d) Instance can be created anywhere in the program

This Site Maintained by Webtech Services


Explanation: If the constructors are defined in private access, then the class can’t be inherited by other classes. This is useful when the class contains static members only. The instances can never be created.

49. The arguments to a copy constructor _____________ Marks: 1 (Correct: a)


a) Must be const b) Must not be cosnt c) Must be integer type d) Must be static

Explanation: The object should not be modified in the copy constructor. Because the object itself is being copied. When the object is returned from a function, the object must be a constant otherwise the compiler creates a temporary object which can die anytime.

50. For explicit call _________________ Marks: 1 (Correct: b)


a) The destructor must be private b) The destructor must be public c) The destructor must be protected d) The destructor must be defined outside the class

Explanation: The destructor must be public for explicit calls. If it is made private or protected then it won’t be accessible outside the class. There is no restriction of definition the destructor outside the class.

51. Choose the correct sequence of destructors being called for the following code. Marks: 1 (Correct: d)

class A{ };

class B{ };

class C: public A, public B{ };

a) ~A(), ~B(), ~C() b) ~B(), ~C(), ~A() c) ~A(), ~C(), ~B() d) ~C(), ~B(), ~A()

Explanation: In multiple inheritance, the constructors are called in the sequence of how they are written in inheritance sequence. And the destructors will be called in the reverse order. This can be cross verified just by printing a message from each destructor
defined in classes.

52. Which feature can be implemented using encapsulation? Marks: 1 (Correct: b)


a) Inheritance b) Abstraction c) Polymorphism d) Overloading

Explanation: Data abstraction can be achieved by using encapsulation. We can hide the operation and structure of actual program from the user and can show only required information by the user.

53. How can Encapsulation be achieved? Marks: 1 (Correct: a)


a) Using Access Specifiers b) Using only private members c) Using inheritance d) Using Abstraction

Explanation: Using access specifiers we can achieve encapsulation. Using this we can in turn implement data abstraction. It’s not necessary that we only use private access.

54. Which is most appropriate comment on following class definition? Marks: 1 (Correct: a)

class Student

int a;

public : float a;

};

a) Error : same variable name can’t be used twice b) Error : Public must come first c) Error : data types are different for same variable d) It is correct

Explanation: Same variable can’t be defined twice in same scope. Even if the data types are different, variable name must be different. There is no rule like Public member should come first or last.

55. What is default access specifier for data members or member functions declared within a class without any specifier, in C++? Marks: 1 (Correct: a)
a) Private b) Protected c) Public d) Depends on compiler

Explanation: The data members and member functions are Private by default in C++ classes, if none of the access specifier is used. It is actually made to increase the privacy of data.

56. The copy constructor can be used to ____________ Marks: 1 (Correct: a)


b) Initialize one object from another object of different c) Initialize more than one object from another object of d) Initialize all the objects of a class to another object of
a) Initialize one object from another object of same type
type same type at a time another class

Explanation: The copy constructor has the most basic function to initialize the members of an object with same values as that of some previously created object. The object must be of same class.

57. Which of the following describes a friend class? Marks: 1 (Correct: a)


a) Friend class can access all the private members of the b) Friend class can only access protected members of d) Friend class can’t access any data member of another
c) Friend class don’t have any implementation
class, of which it is a friend the class, of which it is a friend class but can use it’s methods

Explanation: A friend class can access all the private members of another class, of which it is a friend. It is a special class provided to use when you need to reuse the data of a class but don’t want that class to have those special functions.

58. If data members are private, what can we do to access them from the class object? Marks: 1 (Correct: a)
a) Create public member functions to access those data b) Create private member functions to access those data c) Create protected member functions to access those d) Private data members can never be accessed from
members members data members outside the class

Explanation: We can define public member functions to access those private data members and get their value for use or alteration. They can’t be accessed directly but is possible to be access using member functions. This is done to ensure that the private data
doesn’t get modified accidentally.

59. Object being passed to a copy constructor ___________ Marks: 1 (Correct: a)

This Site Maintained by Webtech Services


a) Must be passed by reference b) Must be passed by value c) Must be passed with integer type d) Must not be mentioned in parameter list

Explanation: This is mandatory to pass the object by reference. Otherwise, the object will try to create another object to copy its values, in turn a constructor will be called, and this will keep on calling itself. This will cause the compiler to give out of memory error.

60. If same message is passed to objects of several different classes and all of those can respond in a different way, what is this feature called? Marks: 1 (Correct: c)
a) Inheritance b) Overloading c) Polymorphism d) Overriding

Explanation: The feature defined in question defines polymorphism features. Here the different objects are capable of responding to the same message in different ways, hence polymorphism.

61. Which type of constructor can’t have a return type? Marks: 1 (Correct: d)
a) Default b) Parameterized c) Copy d) Constructors don’t have a return type

Explanation: Constructors don’t return any value. Those are special functions, whose return type is not defined, not even void. This is so because the constructors are meant to initialize the members of class and not to perform some task which can return some
value to newly created object.

62. The object can’t be __________ Marks: 1 (Correct: d)


a) Passed by reference b) Passed by value c) Passed by copy d) Passed as function

Explanation: Object can’t be passed as function as it is an instance of some class, it’s not a function. Object can be passed by reference, value or copy. There is no term defined as pass as function for objects.

63. Which among the following is false, for a member function of a class? Marks: 1 (Correct: c)
b) Member functions can be defined inside or outside the c) Member functions need not be declared inside the d) Member functions can be made friend to another class
a) All member functions must be defined
class body class definition using the friend keyword

Explanation: Member functions must be declared inside class body, though the definition can be given outside the class body. There is no way to declare the member functions outside the class.

64. Which among the following can show polymorphism? Marks: 1 (Correct: c)
a) Overloading || b) Overloading += c) Overloading << d) Overloading andand

Explanation: Only insertion operator can be overloaded among all the given options. And the polymorphism can be illustrated here only if any of these is applicable of being overloaded. Overloading is type of polymorphism.

65. If class C inherits class B. And B has inherited class A. Then while creating the object of class C, what will be the sequence of constructors getting called? Marks: 1 (Correct: d)
a) Constructor of C then B, finally of A b) Constructor of A then C, finally of B c) Constructor of C then A, finally B d) Constructor of A then B, finally C

Explanation: While creating the object of class C, its constructor would be called by default. But, if the class is inheriting some other class, firstly the parent class constructor will be called so that all the data is initialized that is being inherited.

66. Which among the following can be a concept against encapsulation rules? Marks: 1 (Correct: d)
b) Using char* string pointer to be passed to non-member d) Using any kind of pointer/array address in passing to
a) Using function pointers c) Using object array
function another function

Explanation: If we use any kind of array or pointer as data member which should not be changed, but in some case its address is passed to some other function or similar variable. There are chances to modify its whole data easily. Hence Against encapsulation.

67. Which feature allows open recursion, among the following? Marks: 1 (Correct: a)
a) Use of this pointer b) Use of pointers c) Use of pass by value d) Use of parameterized constructor

Explanation: Use of this pointer allows an object to call data and methods of itself whenever needed. This helps us call the members of an object recursively, and differentiate the variables of different scopes.

68. Which definition best describes an object? Marks: 1 (Correct: a)


a) Instance of a class b) Instance of itself c) Child of a class d) Overview of a class

Explanation: An object is instance of its class. It can be declared in the same way that a variable is declared, only thing is you have to use class name as the data type.

69. Which among the following would destroy the encapsulation mechanism if it was allowed in programming? Marks: 1 (Correct: a)
a) Using access declaration for private members of base b) Using access declaration for public members of base c) Using access declaration for local variable of main()
d) Using access declaration for global variables
class class function

Explanation: If using access declaration for private members of base class was allowed in programming, it would have destroyed whole concept of encapsulation. As if it was possible, any class which gets inherited privately, would have been able to inherit the
private members of base class, and hence could access each and every member of base class.

70. Object is ________ abstraction. Marks: 1 (Correct: c)


a) Object b) Logical c) Real d) Hypothetical

Explanation: Object is real abstraction because it actually contains those features of class. It is the implementation of overview given by class. Hence the class is logical abstraction and its object is real.

71. When is the destructor of a global object called? Marks: 1 (Correct: a)


a) Just before end of program b) Just after end of program c) With the end of program d) Anytime when object is not needed

Explanation: This is because the lifespan of global object is from start of the program, till the end of the program. And hence program end is the end of global object too. Just before the end of program, the destructor will be called to free the acquired resources by
the objects.

72. If a class implements some dynamic memory allocations and pointers then _____________ Marks: 1 (Correct: a)
a) Copy constructor must be defined b) Copy constructor must not be defined c) Copy constructor can’t be defined d) Copy constructor will not be used

Explanation: In the case where dynamic memory allocation is used, the copy constructor definition must be given. The implicit copy constructor is not capable of manipulating the dynamic memory and pointers. Explicit definition allows to manipulate the data as
required.

73. In terms of stream and files ____________ Marks: 1 (Correct: a)


This Site Maintained by Webtech Services
a) Abstraction is called a stream and device is called a b) Abstraction is called a file and device is called a d) Abstraction can’t be defined in terms of files and
c) Abstraction can be called both file and stream
file stream stream

Explanation: Abstraction is called stream to provide a level of complexity hiding, for how the files operations are actually done. Actual devices are called file because in one way or another, those can be considered as single entity and there is nothing hidden.

74. Who invented OOP? Marks: 1 (Correct: a)


a) Alan Kay b) Andrea Ferro c) Dennis Ritchie d) Adele Goldberg

Explanation: Alan Kay invented OOP, Andrea Ferro was a part of SmallTalk Development. Dennis invented C++ and Adele Goldberg was in team to develop SmallTalk but Alan actually had got rewarded for OOP.

75. Which among the following is false for a constructor? Marks: 1 (Correct: b)
d) Constructors may or may not have any arguments
a) Constructors doesn’t have a return value b) Constructors are always user defined c) Constructors are overloaded with different signature
being accepted

Explanation: The constructors are not always user defined. The construct will be provided implicitly from the compiler if the used doesn’t defined any constructor. The implicit constructor makes all the string values null and allocates memory space for each data
member.

76. If programmer have defined parameterized constructor only, then __________________ Marks: 1 (Correct: a)
a) Default constructor will not be created by the compiler b) Default constructor will be created by the compiler c) Default constructor will not be created but called at
d) Compile time error
implicitly implicitly runtime

Explanation: When the programmer doesn’t specify any default constructor and only defines some parameterized constructor. The compiler doesn’t provide any default constructor implicitly. This is because it is assumed that the programmer will create the objects
only with constructors.

77. Which among the following best describes destructor? Marks: 1 (Correct: a)
a) A function which is called just before the objects are b) A function which is called after each reference to the c) A function which is called after termination of the d) A function which is called before calling any member
destroyed object program function

Explanation: The Destructors are special functions which are called just before an object is destroyed. This functions is responsible to free all the allocated resources to the object. Objects are destroyed whenever those go out of scope.

78. If an abstract class has all the private members, then _________ Marks: 1 (Correct: a)
a) No class will be able to implement members of b) Only single inheritance class can implement its c) Only other enclosing classes will be able to implement d) No class will be able to access those members but can
abstract class members those members implement.

Explanation: The classes which inherit the abstract class, won’t be able to implement the members of abstract class. The private members will not be inherited. This will restrict the subclasses to implement those members.

79. Abstraction principle includes___________ Marks: 1 (Correct: c)


a) Use abstraction at its minimum b) Use abstraction to avoid longer codes c) Use abstraction whenever possible to avoid duplication d) Use abstraction whenever possible to achieve OOP

Explanation: Abstraction principle includes use of abstraction to avoid duplication (usually of code). It this way the program doesn’t contain any redundant functions and make the program efficient.

80. Copy constructors are overloaded constructors. Marks: 1 (Correct: a)


a) TRUE b) FALSE c) d)

Explanation: The copy constructors are always overloaded constructors. They have to be. All the classes have a default constructor and other constructors are basically overloaded constructors.

Group C (UNIX): Answer All question(s)


81. Which command is used to list the attributes of a file? Marks: 1 (Correct: c)

a) cp b) list c) ls d) attr

Explanation: ls command is used for listing the attributes of a file or directory. ls command when used with -l displays all the seven attributes of a file.

82. If we wish to delete a remove a file forcefully, we can use ____ option with rm command. Marks: 1 (Correct: d)

a) -i b) -r c) -R d) -f

Explanation: If a file is write-protected, we can remove it forcefully using -f option of rm command. For example, $ rm -f file.txt // removes file.txt forcefully

83. chmod command can be used in ____ ways. Marks: 1 (Correct: b)

a) 3 b) 2 c) 5 d) 0

Explanation: chmod command can be used in two manners i.e. relative (changes are specified to the current permissions) and absolute (final permissions are specified).

84. Ctrl-S stops scrolling of screen output and ________ Marks: 1 (Correct: c)
a) locks terminal b) delete a character c) locks keyboard d) delete a line

Explanation: There are various keyboard commands to try when things go wrong. One of these commands is Ctrl-s which stops scrolling of screen output and locks the keyboard.

85. What is UNIX? Marks: 1 (Correct: a)

a) an operating system b) a text editor c) programming language d) software program

Explanation: UNIX is an operating system developed in the early 1970’s at Bell Labs by Dennis Ritchie, Ken Thompson, and others. It is a multiuser, multitasking and timesharing operating system. The power of UNIX is derived from its commands and their multiple
options.

86. Which of the following symbol is used to indicate the absence of a permission of a file? Marks: 1 (Correct: d)
This Site Maintained by Webtech Services
a) $ b) & c) + d) -

Explanation: ( – ) is used to indicate the absence of a single or set of permissions of a file. For example, if a file has all the three permissions for owner but is only readable by group members and others, then the set of permissions would be, rwx r-- r--

87. Which option performs recursive deletion? Marks: 1 (Correct: d)

a) -r b) -R c) * d) -r and -R

Explanation: With -r or -R option, rm performs a recursive walk in the file hierarchy and searches for every subdirectories and file within this directory, At each stage, it keeps on deleting everything it finds.

88. Which command is used for printing the current working directory? Marks: 1 (Correct: c)

a) HOME b) cd c) pwd d) dir

Explanation: pwd command is used for checking our current directory. Current directory is the directory in which we are currently working. pwd displays the absolute pathname i.e. with respect to the root directory. $ pwd /home/user06/Abdullah

89. Which option is used with cmp command to limit the number of bytes to be compared? Marks: 1 (Correct: a)
a) -n b) -l c) -f d) -b

Explanation: We can limit the number of bytes to be compared by the cmp command by using -n option with it. For example, if we want to compare at most 50 bytes then the command will be written as: $ cmp -n 50 file01 file02

90. What is the output of who command? Marks: 1 (Correct: a)


a) display information about users who are currently
b) display file hierarchy c) display administrator information d) display processes
logged in.

Explanation: who command output the details of the users who are currently logged in to the system. The output includes username, terminal name (on which they are logged in), date and time of their login etc.

91. The write permission for a directory determines that ____________ Marks: 1 (Correct: d)
a) we can write to a directory file b) we can read the directory file c) we can execute the directory file d) we can add or remove files to it

Explanation: The write permission of a directory does not imply that we can write to the directory. Only kernel is allowed to do that. It simply means that we can create or remove files from the directory.

92. Which command compares two sorted files line by line? Marks: 1 (Correct: c)

a) cmp b) diff c) comm d) sort

Explanation: comm command is used for comparing two sorted files line by line. When there is no option specified with comm command it produces three column output. For example, if we want to compare two files namely file01 and file02 then the first column will
contain those entries which are unique to file01 whereas the second column will contain those entries which are unique to file02. The third column will contain the actual information i.e. those entries which are common to both fil01 and file02. $ comm file01 file02
Sanfoundry Project Global Learning UNIX In the above output, ‘Sanfoundry’ and ‘Learning’ are unique in file01 while ‘Global’ and ‘UNIX’ are unique in file02 whereas ‘Project’ is common to both the file.

93. Sometimes we are unable to create a directory because ______________ Marks: 1 (Correct: d)

b) there may be an ordinary file by the same name in the c) the permissions set for the current directory does not d) the directory may exist, there may be an ordinary
a) the directory may already exist in the current directory file, the permissions set for the current directory does not
current directory allow the creation
allow the creation

Explanation: Sometimes we are not able to create directory because of multiple reasons as stated above.

94. What does the following command do? Marks: 1 (Correct: a)

$ mkdir dir dir/dir_01/dir_02

a) create dir, dir_01 and dir_02 b) creates dir_02 c) creates dir only d) throws an error

Explanation: The above command first creates a directory named dir and after that it creates a subdirectory dir_01 under dir. At last, it creates another subdirectory dir_02 under dir_01. Thus a directory tree is formed in which directory dir is the parent directory and
dir_01, dir_02 are subdirectories.

95. What does the following command do? Marks: 1 (Correct: c)

$ wc sample.txt > newfile

a) reads word count from sample.txt b) reads word count from newfile c) reads word count from sample.txt and write it to d) error is produced
newfile

Explanation: > symbol can be used with wc command for redirecting output. For example, the following command will read the input from sample.txt and redirect its output to newfile. $ wc sample.txt > newfile

96. Device files are used by the kernel for operating the device. Marks: 1 (Correct: a)
a) TRUE b) FALSE c) d)

Explanation: Device files are nothing but special files which does not contain a stream of characters but some attributes related to the devices which govern the operation of a device. The kernel reads this file for the attributes to perform operations on any device.

97. Hard linked files are provided with the same inode number as the original one. Marks: 1 (Correct: a)
a) TRUE b) FALSE c) d)

Explanation: Hard linked files are provided with the same inode number as the original file so they refer to the same physical location of the file.

98. How can we copy a file into our current directory? Marks: 1 (Correct: b)

a) cp file1 b) cp file1. c) cp file* d) none of the mentioned

Explanation: For creating a copy of a file into our current working directory we use the shorthand notation (.). For example, cp file1 . will create a copy of file1 into our current working directory with the same name.
This Site Maintained by Webtech Services
99. Which files will be displayed by the following command: Marks: 1 (Correct: b)

cat *file*
a) all files in the directory b) all files with filename containing ‘file’ c) no files will be displayed d) a single file

Explanation: Since * is a meta-character, here it is being used for pattern matching. So above command will search all the files in the directory having ‘file’ as a part of their filename. After that it will concatenate the output of all the searched files and display them on
the terminal.

100. Which command is used for printing a file? Marks: 1 (Correct: a)

a) lp b) pr c) pg d) more

Explanation: lp command is used for printing a single copy of the file specified as an argument to lp command. For example, $ lp abd.txt Request id id prl-890 (1 file ) lp command notifies the request-id i.e. a combination of printer name(rpl) and job number (890).

101. Which option is used with cat command for displaying non-printable characters? Marks: 1 (Correct: a)
a) -v b) -n c) -x d) -a

Explanation: If the file that we want to display contains nonprintable ASCII characters, then to display those characters we use -v option with the cat command. -n option is used for displaying the contents of the file along with line numbers.

102. POSIX is a set of standards specified for establishing compatibility between operating systems. Marks: 1 (Correct: a)
a) TRUE b) FALSE c) d)

Explanation: POSIX- Portable Operating System Interface for Computer Environment is basically a set of standards specified by IEEE for establishing compatibility between operating systems, especially which are UNIX based. For example, if we write a program
relying on POSIX standards, we can easily port it among a large family of Unix derivatives (including Linux).

103. Options are also arguments but begin with a -. Marks: 1 (Correct: a)
a) TRUE b) FALSE c) d)

Explanation: Arguments are parameters which are specified along with commands so that the command can perform an operation or take input from that parameter while options are also arguments but they are predetermined i.e. they perform a particular task. For
example, echo hello. In this command hello is an argument while in ls – l, -l is an option.

104. Which command is used for renaming files? Marks: 1 (Correct: b)

a) rename b) mv c) cp d) move

Explanation: mv command is used for renaming files. This command does not create a copy of the file, it simply renames it. To rename file1 to file2 simply type, $ mv file1 file2

105. Which option is used for counting the number of characters in a file only. Marks: 1 (Correct: c)

a) -l b) -W c) -c d) -w

Explanation: -c option when used with wc command display only the number of characters in the specified file. $ wc -c file01 45 // number of characters in file01

106. What if the destination file specified in mv command already exists? Marks: 1 (Correct: c)
a) it will be deleted b) it will not be affected c) it will be overwritten d) an error will be produced

Explanation: If the destination file already exists, then the contents of this file will be overwritten with the contents of a source file. For example, mv file01 dir01. If there already exists a file named dir01, then the contents of dir01 will be overwritten with the contents
of file01.

107. cd /bin/user/directory/abc is an example of relative pathname. Marks: 1 (Correct: b)

a) TRUE b) FALSE c) d)

Explanation: Whenever the pathname is relative to the root it is an example of relative pathname. The above pathname is also relative to the root, so it is an example of relative pathname.

108. Which of the following characters specify the user and group category? Marks: 1 (Correct: a)
a) ‘u’ and ‘g’ b) ‘g’ and ‘o’ c) ‘us’ and ‘gr’ d) ‘u’ and ‘o’

Explanation: Each character specifies a particular category of users as follows: ‘u’ stands for a user, ‘g’ for ‘group’ ‘o’ for ‘others’.

109. For moving two level up in the file hierarchy system using cd command once, we separates ( . . ) by which symbol? Marks: 1 (Correct: d)

a) ? b) $ c) * d) /

Explanation: For changing your directory to the parent of current directory we can use ( . . ) with cd command. If we want to move more than one level up then we can use the ( . . ) separated by / . $ cd . . / . . -moves two level up

110. Which option is used with ls to display attributes of the directory ? Marks: 1 (Correct: c)

a) -a b) -ld c) -d d) -o

Explanation: ls command when used with directory name as an argument, lists all the files in the directory. To force ls to list the attributes of the directory we use the -ld option. $ ls -ld drwxr-xr-x 5 george users 4096 Sep 25 08:30 go drwx------ 3 george users 4096
Sep 27 10:49 irc drwxr-xr-x 2 george users 32768 Oct 4 09:15 logs drwxr-xr-x 8 george users 4096 Oct 2 17:13 src

111. What does the following command do? Marks: 1 (Correct: d)

cp -u * dir_file
d) update all files in the current working directory and
a) copy all files to directory dir_file b) update all files c) delete all files
copy newer ones to directory dir_file

Explanation: update all files in the current working directory and copy newer ones to directory dir_file
This Site Maintained by Webtech Services
112. What is a directory file? Marks: 1 (Correct: b)
b) a directory containing details of the files and
a) a directory containing data c) a directory contains files d) a directory containing data and files
subdirectories it contains

Explanation: A directory file contains no data but some details of the subdirectories and files that it contains. Directory files contain an entry for every file and subdirectory in it and each entry has some necessary information regarding files and subdirectories.

113. What are meta-characters? Marks: 1 (Correct: a)


a) special characters having predefined meaning to the
b) special symbols c) shell symbols d) command symbols
shell

Explanation: meta-characters are special characters having a predefined meaning to the shell. They are used as wild cards for special purposes like pattern matching, output redirecting etc. *, |, < are meta-characters.

114. When we log in, the UNIX places us in a directory, called ______ directory Marks: 1 (Correct: a)
a) home b) main c) parent d) current

Explanation: When we log in, the system automatically places us in a directory called Home directory. We can change our directory if we want and can also view our home directory using the shell variable, HOME.

115. A file named abd.txt has the following set of permissions Marks: 1 (Correct: a)

-rwxrwxrwx

All the three operations i.e read, write and execute can be performed on the file by file owner, group owner and others.

a) TRUE b) FALSE c) d)

Explanation: UNIX provides a three tired file protection system that determines the file access rights i.e. the permissions are dived into three groups as r w x r w x r w x The first group has all the three permissions i.e. file is readable, writable and executable by the
file owner. The second group also has all the three permissions i.e. file is readable, writable and executable by the group owner. The third group also has all the three permissions i.e. file is readable, writable and executable by others who are neither a part of the
group nor they are an owner of the file. Normally this set of permissions is too dangerous!

116. UNIX treats everything as a file. Marks: 1 (Correct: a)


a) TRUE b) FALSE c) d)

Explanation: All physical devices such as printers, hard disk are treated as files by the UNIX system. Even the kernel, shell and main memory is treated as a file by UNIX operating system.

117. What are links referred to as in file attributes? Marks: 1 (Correct: a)


a) number of filenames of a single file that are maintained
b) number of duplicates of a single file c) number of copies of a single file d) number of files present in a directory
by the system

Explanation: Links are defined as the number of filenames of a single file that are maintained by the system. This file can be accessed through as many filenames as there is a number of links to that file.

118. What is the function of cp command in UNIX? Marks: 1 (Correct: c)

a) list all the available files in the current directory b) delete a given file c) cp is a command used for copying files and d) change the directory
directories

Explanation: cp command is basically used for creating a copy of source file or a group of files. The syntax of the command requires at least two filenames to be specified. If both the files specified are ordinary files, the first file will be copied to the second file. The
syntax of cp command is cp source_filename destination_filename. The contents of the source file will be copied to the destination file in the same directory. $ cp file_01 file_02 // copies file_01 to file_02

119. Which of the following is default permission set for directories? Marks: 1 (Correct: b)

a) rw-rw-rw- b) rwxrwxrwx c) r-r-r- d) rw-rw-rwx

Explanation: The default permission set for an ordinary file is rwxrwxrwx i.e. it is readable, writable, executable by owner, group members and others.

120. Which command is used to change the permissions of a file? Marks: 1 (Correct: a)

a) chmod b) ch c) chown d) chgrp

Explanation: The chmod (change mode) command is used to change the permissions of files. This command can only be run by the owner of the file or by the super user.

Back

This Site Maintained by Webtech Services

You might also like