C programming skills for a junior embedded software developer to prepare for a job interview Flashcards

(77 cards)

1
Q

What is the purpose of the ‘main’ function in a C program?

A

The ‘main’ function is the entry point of a C program where execution starts.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

True or False: In C, a pointer is a variable that stores the memory address of another variable.

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Fill in the blank: The standard library function used to allocate memory dynamically in C is called _____ .

A

malloc

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Which of the following is a correct way to declare an integer pointer in C? (a) int p; (b) int *p; (c) pointer int p;

A

(b) int *p;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What does the ‘volatile’ keyword indicate when used in a variable declaration?

A

It indicates that the variable may be changed by something outside the control of the program, preventing the compiler from optimizing it.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What does ‘C’ stand for in the C programming language?

A

The letter ‘C’ does not stand for anything; it is simply the name of the programming language.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

True or False: C is a high-level programming language.

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Fill in the blank: The __________ operator is used to access members of a structure in C.

A

dot

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is the purpose of a pointer in C?

A

A pointer is used to store the address of another variable.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Which of the following is a valid variable declaration in C? (a) int 1number; (b) float number1; (c) char @name;

A

b) float number1;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is the output of the following code: printf(‘%d’, 5 + 3);?

A

8

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What does ‘malloc’ function do in C?

A

It allocates a specified amount of memory during runtime.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

True or False: C supports function overloading.

A

False

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is the purpose of the ‘return’ statement in a function?

A

It ends the function and optionally returns a value to the caller.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Fill in the blank: The __________ statement is used to create a loop that continues until a specified condition is false.

A

while

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What is an array in C?

A

An array is a collection of variables of the same type stored in contiguous memory locations.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

What is the correct syntax to declare a function in C?

A

return_type function_name(parameter_type parameter_name) { /* function body */ }

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

True or False: In C, a string is an array of characters terminated by a null character.

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

What is the purpose of the ‘typedef’ keyword in C?

A

It is used to create an alias for an existing data type.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

Which of the following is the correct way to comment a single line in C? (a) // comment (b) /* comment */ (c) # comment

A

a) // comment

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

What is the significance of the ‘main’ function in a C program?

A

It is the entry point of the program where execution begins.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

Fill in the blank: The __________ function is used to read input from the user in C.

A

scanf

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

What does the ‘break’ statement do in a loop?

A

It terminates the loop and transfers control to the statement following the loop.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

True or False: In C, all variables must be declared before they are used.

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
What is a structure in C?
A structure is a user-defined data type that allows grouping of variables of different types.
26
What is the purpose of the 'sizeof' operator?
It returns the size, in bytes, of a data type or variable.
27
Which of the following is a logical operator in C? (a) && (b) + (c) -
a) &&
28
What is the difference between '==' and '=' in C?
'==' is used for comparison, while '=' is used for assignment.
29
Fill in the blank: The __________ directive is used to include standard input and output functions in a C program.
#include
30
What is the function of the 'continue' statement in a loop?
It skips the current iteration and continues with the next iteration of the loop.
31
True or False: C allows for recursion in functions.
True | https://www.youtube.com/watch?v=kepBmgvWNDw
32
What is a union in C?
A union is a user-defined data type that allows storing different data types in the same memory location.
33
Which keyword is used to define a constant in C?
const
34
What does the 'enum' keyword do in C?
It defines a variable that can hold a set of predefined constants.
35
What is the output of the following code: printf('%d', 10 / 3);?
3
36
What is the purpose of header files in C?
Header files contain declarations of functions and macros to be shared among multiple source files.
37
Fill in the blank: The __________ function is used to free dynamically allocated memory.
free
38
What is the difference between 'struct' and 'class' in C?
'struct' is used in C, while 'class' is used in C++ for object-oriented programming.
39
True or False: C supports multiple inheritance.
False
40
Which of the following is a valid pointer declaration? (a) int *p; (b) int p*; (c) *int p;
a) int *p;
41
What does the 'volatile' keyword indicate in C?
It tells the compiler that the variable can be changed unexpectedly, preventing optimization.
42
What is a segmentation fault?
A segmentation fault is an error that occurs when a program tries to access a memory location that it is not allowed to access.
43
True or False: C allows implicit type conversion.
True
44
What is the purpose of the 'static' keyword in C?
It restricts the visibility of a variable or function to the file in which it is defined.
45
Fill in the blank: The __________ function is used to terminate a program in C.
exit
46
What is the role of the preprocessor in C?
The preprocessor processes directives before compilation, such as including header files and macro definitions.
47
Which of the following is an example of a conditional statement in C? (a) for (b) if (c) switch-case
b) if
48
What does 'bss' stand for in memory segments?
Block Started by Symbol
49
True or False: The 'sizeof' operator can be used with user-defined types.
True
50
What is the purpose of the 'break' statement in a switch-case statement?
It exits from the switch-case block after executing a case.
51
Fill in the blank: The __________ operator is used to perform bitwise AND in C.
&
52
What is the difference between '++i' and 'i++'?
'++i' increments 'i' before the value is used, while 'i++' increments 'i' after the value is used.
53
What is a memory leak?
A memory leak occurs when a program allocates memory but fails to release it back to the operating system.
54
True or False: The 'goto' statement is generally recommended for use in C programming.
False
55
What does the 'extern' keyword do?
It declares a variable that is defined in another file or scope.
56
Fill in the blank: The __________ function is used to copy strings in C.
strcpy
57
What is the purpose of the 'assert' macro?
It is used to perform runtime checks and validate assumptions in the code.
58
What does 'volatile' keyword imply about a variable's value?
The value of a volatile variable may change at any time without any action being taken by the code the compiler finds nearby.
59
What is a callback function?
A callback function is a function that is passed as an argument to another function and is invoked at a certain point.
60
True or False: C allows for dynamic memory allocation.
True
61
What is the purpose of the 'sizeof' operator?
It returns the size in bytes of a variable or data type.
62
Fill in the blank: The __________ operator is used to compare two values for inequality.
!=
63
What does the 'continue' statement do in a loop?
It skips the current iteration and proceeds to the next iteration of the loop.
64
What is a dangling pointer?
A dangling pointer is a pointer that does not point to a valid object of the appropriate type.
65
True or False: C is platform-dependent.
True
66
What is the difference between 'struct' and 'typedef struct'?
'struct' defines a structure, while 'typedef struct' creates an alias for a structure type.
67
What is a null pointer?
A null pointer is a pointer that does not point to any valid memory location.
68
Fill in the blank: The __________ function is used to concatenate two strings in C.
strcat
69
What is the purpose of the 'volatile' keyword?
It informs the compiler that the value of a variable may change unexpectedly.
70
What is the use of the 'switch' statement?
The 'switch' statement allows the execution of different parts of code based on the value of a variable.
71
True or False: The C programming language was developed in the 1970s.
True
72
What is the primary purpose of using header files in C?
To declare functions and macros that can be shared across multiple source files.
73
What does 'printf' function do?
It outputs formatted text to the standard output (usually the console).
74
Fill in the blank: The __________ operator is used for bitwise OR in C.
|
75
What is a function prototype?
A function prototype is a declaration of a function that specifies its name, return type, and parameters.
76
True or False: The 'main' function can return a value other than 0.
True
77
How do you prevent memory leaks in C?
Always free() memory allocated with malloc() or calloc() Avoid unnecessary dynamic allocation in embedded systems Use tools like Valgrind or custom debug allocators Track allocations with logs or counters Initialize pointers to NULL and check before freeing Avoid memory allocation in ISRs or frequently called functions