Showing posts with label Technical Interview Questions. Show all posts
Showing posts with label Technical Interview Questions. Show all posts

Tuesday, November 6, 2018

LP Objective QA

11. In message queue , the first parameter is key value , the second parameter is ________
a) key value  b) flag value   c) register value

12. Which of the following function is used to retrieve message from message queue
a) msgget()   b) msgsend()  c) msgrcv()

13. Which one of the following is not included in the message queue
a) queues  b) envelopes   c)stack

14 .Memory for a message as well as metadata is holded by
a) stack  b) envelope  c)queue

15. Which of the following supports the receiving with message handlers
a) GNUNET_CLIENT_CONNECTION      b) GNUNET_SERVER_CLIENT     c) GNUNET_MESH_TUNNEL

16. Which of the following supports the receiving with message handlers
a) unary  b) tertiary  c) binary

17. The special key value _________ allows to create the semaphore
a) IPC_PRIVATE   b) IPC_PUBLIC   c) IPC_PROTECTED

18.________bits are the permissions for the semaphore
a) 5   b) 9   c) 1

19. Which is used for initializing a semaphore to a known value
a) SETVAL   b) GETVAL   c)SEMVAL

20. _______deletes the semophore identifier
a) IPC_REMOVE    b) IPC_RMID    c) IPC_DELETE

21. The command which is used to change its ownership or permissions if you are the semaphore creator is
a) semget()   b) semctl()  c) semop()

22. A POSIX Semaphore structure defines ________semaphore
a) single   b) double   c) triple

23. Which of the following command is used to initialize a semaphore structure
a) sem_getvalue()   b) sem_init()   c)sem_open()


24. In the function semaphore_v() , the semop member of the structure sembuf is set to ___
a) 0  b) 1  c)2

25. Which function provides a mean of passing data between two programs
a) sem()  b) pipe()  c) sock()

Monday, November 5, 2018

Linux Programming

1. Inter process communication includes__________ synchronization
a) thread   b) data   c)process

2. Which of the following were included in IPC on single computer system
1. Shared memory
2. Messages
3. Pipes
a) Only 1   b) Only 2   c) All 3 of them

3. Which of the following communication is allowed by pipe
a) unidirectional   b) bidirectional   c)multidirectional

4. How the pipes synchronize the two processes
a) manually   b) automatically    c) systamatically

5. Which command is used to make a pipe to wait for the data to be available from the user terminal
a) od  b)wait  c)id

6. Unnamed pipes were also known as
a) FIFO  b) LIFO  c)anonymous

7. Named pipes is used for communication between _________processes
a) interrealted   b) related  c)unrelated

Monday, April 4, 2016

'Register' Storage Class Specifier

'register' storage class is same as 'auto' except that 'register' variables are stored in CPU registers compared to 'auto' where 'auto' variables are stored in RAM. The scope of 'register' class variable is same as 'auto' class variable, i.e. they can't be accessed outside the code block they are declared. 'register' variables will also be initialized with garbage value.

Example of register storage class is given below
  1. #include <stdio.h>
  2. int main( )
  3. { //Code block 1
  4.  
  5. auto int a = 1;
  6. { //Code block 2
  7.  
  8. auto int a = 2;
  9. { //Code Block 3
  10.  
  11. auto int a = 3;
  12. printf ( "\n Value of 'a' in Code Block 3: %d", a);
  13. }
  14. printf ( "\n Value of 'a' in Code Block 2: %d", a);
  15. }
  16. printf ( "\n Value of 'a' in Code Block 1: %d", a);
  17. }
  18.  
  19. Output:
  20. Value of 'a' in Code Block 3: 3
  21. Value of 'a' in Code Block 2: 2
  22. Value of 'a' in Code Block 1: 1
Since CPU register access is faster than memory access, declaring frequently accessed variables as 'register' will improve the performance of program. But one important thing to note about 'register' variable is, it's not guaranteed that those variables will be stored in CPU registers because number of registers is very limited for a CPU. So, if all the registers are allocated for other variables or purposes, then a variable will get stored in RAM even if it's declared as 'register' type.


Also, you cannot request address of a register variable using address operator (&). This will result in compilation error because 'register' variables might not be stored on RAM.

Thursday, March 31, 2016

Difference between Structures and Unions

Structure and union both are user defined data types. The main difference between structure and union is that union uses same memory location for all the member variables hence the size of the union is the size of the largest member variable but structure uses different memory location for all the members. Let’s take an example:
union my_union
{ int my_int;
char my_char2;
char my_char1; } my_union;
int my_int;
struct my_struct { char my_char1;
} my_struct;
char my_char2;
Now if we execute sizeof function over my_struct and my_union then we will see that the output as 4 for union and 6 for structure. As for structure it is simple 4 for integer and 2 for 2 character variables but if for union it happens because of the union’s property of sharing memory location to all members. Union allocates memory equal to the size of the member variable which takes largest in the memory. Here since integer takes 4 bytes and character takes 1 byte each that’s why it takes 4 bytes of memory hence it outputs 4.

Thursday, March 24, 2016

Member Variables

All the subfields i.e the primitive data type variables in structures are called member variables. We can access these member variables using dot(.) operator. We can set and retrieve the member variable of student structure as shown below.
student student_1 = {0};
student_1.roll_number = 20;
strcpy(student_1.name,”Denis Ritchie”);
student_1.class = 12;
student_1.section = ‘A’;
student_1.marks = 96.9;
strcpy(student_1.school_name,”a4academics.com”);

Monday, February 1, 2016

Logical operator

There are three logical operators in C language, &&, ||, !
OperatorNameDescriptionExample
&&'Logical AND' Operator'AND' operator returns true if both the operands it operates on evaluates to true (non-zero), else return falsea && b returns true if both a and b are non-zero
||'Logical OR' Operator'OR' operator returns true if any of the operands it operates on evaluates to true (non-zero), else return falsea || b returns true if either a or b are non-zero
!'Logical NOT' Operator'NOT' operator is a unary operator (it operates only on one operand). It returns true if the operand is false and returns false if the operand is true!a returns true if a is false. Else returns false

Examples of Logical Operators

  1. #include <stdio.h>
  2.  
  3. int main(void) {
  4. int a = 5, b = 6;
  5. printf("(a == 5) && (b == 7) : %d\n", (a == 5) && (b == 7));
  6. printf("(a == 5) || (b == 7) : %d\n", (a == 5) || (b == 7));
  7. printf("!(a == 5) : %d", !(a == 5));
  8. return 0;
  9. }
  10.  
  11. Output:
  12. (a == 5) && (b == 7) : 0
  13. (a == 5) || (b == 7) : 1
  14. !(a == 5) : 0

Sunday, January 31, 2016

Relational operator

Relational operators are binary operators(operates on two operands) and are used to relate or compare two operands. There are four relational operators in C (i.e <, <=, >, >=). If the relationship between the operands is correct, it will return 1 and returns 0 otherwise.
Apart from four relational operators, C has two equality operator (== and !=) as well for comparing operands. Now let's take a look at different relational and equality operators and how they operate on the operands.
OperatorNameDescriptionExample
<'Less than' operatorChecks if the first operand is less than second operand and returns 1 if it's true, else returns 010 < 5 returns 0 and5 < 10 returns 1
<='Less than or equals to' operatorChecks if the first operand is less than or equals to second operand and returns 1 if it's true, else returns 010 <= 10 returns 1 and 10 <= 5 returns 0
>'Greater than' operatorChecks if the first operand is greater than second operand and returns 1 if it's true, else returns 010 > 5 returns 1 and5 > 10 returns 0
>='Greater than or equals to' operatorChecks if the first operand is greater than or equals to second operand and returns 1 if it's true, else returns 010 >= 10 returns 1 and 5 >= 10 returns 0
==Equality operatorChecks if the two operands are equal are returns 1 if it's true, else returns 010 == 10 returns 1 and 10 == 1 returns 0
!=Non-equality operatorChecks if the two operands are equal are returns 1 if they are not equal, else returns 010 != 10 returns 0 and 10 != 1 returns 1

Thursday, January 28, 2016

Assignment Operator

Assignment operator assigns value of the expression on the right side to left side variable. The base assignment operator is '='. In C, you can use this operator like the following variable = expression
Here variable can be any kind of a variable and expression can be a simple constant, another variable or may be a more complex expression, like a formula. The value of the expression will be evaluated and assigned to the variable. But, there are some things to note about the assignment operator.


If the value of the expression on the right side is not same data type as variable on the left, then the value of the expression will be converted to same data type as the variable. Suppose, the expression is a floating point number and the variable is an integer. Then, the floating point number will be converted to integer and then will be assigned to the variable. It is better to use same data types on both sides unless it is a must, else it may lead to information loss.

C also allows multiple assignment statement like variable1 = variable2 = ... = variableN = expression.


This means, the value of the expression will be assigned to 'variableN', which in turn will be assigned to the variable left of 'variableN' and it propagates till 'variable1'. So, after the execution of multiple assignment operation, all the variables will have the same value.

Monday, January 25, 2016

C Operators - Arithmetic, Assignment, Relational and Logical

Operator Basics

Operators in C language are symbols which tells the compiler to perform some mathematical calculations or logical operations (we will look at in a while) on the variables and constants. For example, consider the mathematical operation "10 + 2 - a". Here '+' and '-' are called operators and the values on which operators work ('10', '2', and 'a') are known as operands. C programming language has wide variety of operators which are categorised into different groups based on the type of operations they perform.

Operator Arity

Arity implies the number of operands the operator is defined to work on. Based on that we have operators of following articles
ArityDescription
Unary OperatorOperates on single operand.
Binary OperatorOperates on two operands, For example: '/' (used for division).
Ternary OperatorOperates on three operands. Example : conditional operator (we will discuss about it in this chapter).
n-ary OperatorOperators that operate on more than 3 operands.

Sunday, January 24, 2016

String Constants/Literals

String constants consist of any number of consecutive characters in enclosed quotation marks ("). String constants can have any valid character as part of it, including escape sequences. Example of string literal is given below
"Hello World!"
Some string constants can span multiple lines like the one given below
"First line \nSecond line \nThird line"
// Above statement when printed will look like as given below
First line 
Second line 
Third line
If you want to declare a string constant with quotation marks or backslash as part of the string, then you have to include proper escape character (\) for that. For example if you want a double quote (") as part of your string (like - Press the "Enter" button) you can do it as given below

Thursday, January 21, 2016

Character constants

Character constants hold a single character enclosed in single apostrophes. Characters are short integers. So, it can hold an integer value as well (maximum value character constants can hold is 127 and 255 for unsigned character constants). Also, different characters have associated integer values (like 'A' is 65, 'a' is 97 etc.). These values are standard and known as ASCII (American Standard Code for Information Interchange).
There are some characters which have special use in C language compared to other characters. They are preceeded by a backslash(\) (like \n, \b). These characters are called escape sequences. Below, you can find examples of escape sequences available in C.
CharactersEscape sequence
bell\a
backspace\b
horizontal tab\t
vertical tab\v
newline\n
form feed\f
carriage return\r
quotation mark\"
apostrophe\'
question mark\?
backslash\\
null\0
For example, using '\n' in printf statement will feed a line in the output. Character constants can hold escape sequences too. Examples of few of the character constants are given below.

Wednesday, January 20, 2016

Floating Point Constants/Literals

Floating point constants represents the floating point numbers, as the name suggests ie; numbers like 1.2, 3.6894 etc. In C programming language, we can represent a floating point constant in two ways,
  • Decimal point format or in
  • Exponent format.
In order to represent a floating point constant in decimal format, you need to include the decimal point (.) in the number. Floating point numbers can be expressed in exponent format like 1.23E-4 or 1.23e-4. It is another way to represent 1.23 x 10-4. The number after E can be signed, but should always be an integer. So, 3.56E1.2 is an invalid floating point constant. Some valid floating point constants in C are given below
3.968421
3968421E-6L
// Both of the above float literals represent the same value.

Tuesday, January 19, 2016

C Constants and Literals

Constants in C programming language, as the name suggests are the data that doesn't change. Constants are also known as literals. There are five types of constants or literals available in C programming language as shown below.
  • Integer Constants
  • Floating-point Constants
  • Character Constants
  • String Constants
  • Enumeration Constants

Integer Constants/Literals

Integer constants, as the name suggests, are integer values ie; numbers like 1, 20 etc. In C programming language, we can have integer constants of 3 different bases (or radix) namedDecimal (Base 10), Hexadecimal (Base 16) or Octal (base 8). During the declaration of an integer constant, a prefix is used along with the value to specify the base or radix.
  • For decimal literals, no prefix is used.
  • Prefix used for hexadecimal: 0x / 0X
  • Prefix used for octal: 0

Examples of different integer constants
123        /* decimal constant*/
0x9b       /* hexadecimal constant*/
0X9c       /* hexadecimal constant*/
0456       /* octal constant*/
In C programming, you can use upper case or lower case letters (ABCDEF or abcdef) as part of hexadecimal literals.

Wednesday, January 13, 2016

C Type Casting with examples - float to int / int to char / int to long

The value of a variable or expression can be converted to another data type if desired. It is called type casting or type conversion. If you have a variable of data type long and you want to assign it to an int type variable, type casting can be used for that purpose. To type cast a variable or expression it must be preceded by the desired datatype as follows.
(data type) expression;

Why do we need type casting?

Type casting would be pretty handy when your inputs to an operation is of a particular type and you need more precision in the output. Let's see the use of type casting through a simple example
  1. #include <stdio.h>
  2.  
  3. int main()
  4. {
  5. int value1 = 10, value2 = 3;
  6. float result;
  7. result = value1 / value2;
  8. printf("Result without type casting: %f", result);
  9. return 0;
  10. }
  11.  
  12. Output:
  13. Result without type casting: 3.000000
In the above example we assign the result of division operation to float type variable result. The result is supposed to be 3.333333. But we get the result as 3.000000. Can you think why? Because the two operands of the expression, value1 and value2 are of int type. This causes compiler to treat the result also as integer; that means, it will ignore the decimal part of the result and store the integer result in float variable.

Tuesday, January 12, 2016

C Qualifiers - Constant and Volatile type Qualifier

C has some basic data types like 'int', 'float', 'char' etc. Each of which can hold a data of a specific type and has a set of specific properties defined for them. But what if you need to modify the properties of them? For example, if you want to make an 'int' variable constant, that means it's value shouldn't be changed from any where else in the program except the variable definition part. C type qualifiers can be used for such purposes.

'Const' Qualifier in C

Two type qualifiers available in C are 'const' and 'volatile'.
'Const' qualifier will impose a restriction on the variable, such a way that its value can't be changed or modified. The main use of 'const' is to define constants in your program; so that it's values can't be changed. Please take a look at the example given below to understand the use case of 'const' qualifier
  1. #include <stdio.h>
  2. // PI is defined as 'const' so that you may not change it's value accidentally.
  3. const float PI = 3.14;
  4.  
  5. double find_area(float radius) {
  6. return PI * radius * radius;
  7. }
  8.  
  9. int main() {
  10. printf("Area: %f", find_area(5.5));
  11. return 0;
  12. }
  13.  
  14. Output:
  15. Area: 94.985001

'Volatile' Type Qualifier in C

If a variable is declared as 'volatile', its value can be changed from outside the program. Declaring a variable with 'volatile' is actually a hint to the compiler to not perform any optimizations on the access restrictions of the variable. Let's take a look at it with the help of an example using 'volatile' keyword.