Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 16

C Interview Questions

1. What are the storage classes in C?


 Auto
 Register
 Static
 External
2. What is the difference between static and extern in C?

The static storage class is used to declare an identifier that is a local variable either
to a function or a file and that exists and retains its value after control passes from
where it was declared.

The extern storage class is used to declare a global variable that will be known to the
functions in a file and capable of being known to all functions in a program. This storage
class has a duration that is permanent

3. What is the build process in C?


 Pre-Processing
 Compiler
 Assembling
 Linking
4. What is mean by call by value and call by reference?

The value or data of variable passed to function. It is known as call by value or pass
by value. So if the data passed is modified inside the function, the value is only changed
in the variable used inside the function

Instead of passing value of variable, pass the address of variable. It is known as call
by reference or pass by reference. Any updates made inside the called function will
modify the original value since we are directly modifying the content of the exact
memory location

5. What is meant by Function Pointer?


A Function pointer is a variable that stores the address of a function that can
later be called through that function pointer.
6. Difference between structure and union?

Structure Union
 In Structure, each member get  In union, the total memory space is
separate space in memory. The allocated to be equal to the
total memory required to store a member with largest size. All other
structure variable is equal to the members share the same memory
sum of size of all member. space.
 Example :  Example
struct student union student
{ {
int id int id
char name char name
float marks float marks
}s1 }s1
In above example, 7 bytes (2 + 1 + 4) are In above example, 4 bytes are required to
required to store the structure variable s1. store the union variable s1, because a
variable mark is float type and it have
largest size (4 byte).
 We can access any member in any  We can access only that variable
sequence whose value is recently stored.
s1.id = 20; s1.id = 20;
s1.marks = 91.2; s1.marks = 91.2;
printf(“%d”,sl.id); printf(“%d”,sl.id);

o/p = 20; o/p = 8723;


The above code will work fine, but will The code will show erroneous output. The
show erroneous (wrong) output in union. value of id is lost a most recently. We have
stored value in marks.
MATLAB Interview questions
1. What Is the MATLAB Workspace?
The MATLAB workspace consists of the variables you create and store in memory
during a MATLAB session. You add variables to the workspace by using functions,
running MATLAB code, and loading saved workspaces.
2. Types of Workspace and tell difference between it?
 Base Workspace
 Function Workspace
The base workspace stores variables that you create at the command line. This
includes any variables that scripts create, assuming that you run the script from the
command line or from the Editor. Variables in the base workspace exist until you clear
them or end your MATLAB® session.
Functions do not use the base workspace. Every function has its own function
workspace. Each function workspace is separate from the base workspace and all other
workspaces to protect the integrity of the data. Even local functions in a common file
have their own workspaces. Variables specific to a function workspace are called local
variables. Typically, local variables do not remain in memory from one function call to
the next.
3. What Are Nested Functions?
A nested function is a function that is completely contained within a parent
function. Any function in a program file can include a nested function.
The primary difference between nested functions and other types of functions is that
they can access and modify variables that are defined in their parent functions. As a
result:
 Nested functions can access and modify variables in the workspaces of the
functions that contain them
 Nested functions can use variables that are not explicitly passed as input
arguments.
 In a parent function, you can create a handle to a nested function that contains
the data necessary to run the nested function.
4. What is meant by Persistent Variables?
When you declare a variable within a function as persistent, the variable retains
its value from one function call to the next. Other local variables retain their value only
during the current execution of a function. Persistent variables are equivalent to static
variables in other programming languages.
Declare variables using the persistent keyword before you use them. MATLAB®
initializes persistent variables to an empty matrix, [].
5. What is meant by Global variable?
Global variables are variables that you can access from functions or from the
command line. They have their own workspace, which is separate from the base and
function workspaces.
 Any function can access and update a global variable. Other functions that use
the variable might return unexpected results.
 If you unintentionally give a "new" global variable the same name as an existing
global variable, one function can overwrite the values expected by another. This
error is difficult to diagnose.
If you use global variables, declare them using the global keyword before you access
them within any particular location (function or command line).
6. What is meant structure and cell?
Structure array contain data in fields that you access by name. It accept different
data type and size.
Cell arrays contain data in cell that you can access by numeric indexing. . It
accepts different data type and size.
7. What is meant by script and function script?
Scripts − script files are program files with .m extension. In these files, you write
series of commands, which you want to execute together. Scripts do not accept inputs
and do not return any outputs. They operate on data in the workspace.

Functions − functions files are also program files with .m extension. Functions
can accept inputs and return outputs. Internal variables are local to the function.
8. Difference between script and function script?
 Scripts do not accept inputs and do not return any outputs.
 Functions can accept inputs and return outputs.
MATLAB Simulink Interview Questions

1. What is meant by sample time?


The sample time of a block is a parameter that indicates when, during
simulation, the block produces outputs and if appropriate, updates its internal state.
The internal state includes but is not limited to continuous and discrete states that
are logged.
2. What is meant by bus creator, bus selector, mux, and demux?

Bus Creator: The Bus Creator block combines a set of signals into a bus. To bundle a
group of signals with a Bus Creator bloc. You can connect any type of signal to the
inputs, including other bus signals

The Bus Creator block accepts and outputs real or complex values of any data type
supported by Simulink, including fixed-point and enumerated data types, as well as
bus objects.

Bus selector Select signals from incoming bus. The block can output the specified
elements as separate signals or as a new bus.

When the block outputs separate elements, it outputs each element from a separate
port from top to bottom of the block.

Mux: The Mux block combines its inputs into a single vector output. An input can be
a scalar or vector signal. All inputs must be of the same data type and numeric type.
The elements of the vector output signal take their order from the top to bottom, or
left to right, input port signals.

Demux: The Demux block extracts the components of an input signal and outputs
the components as separate signals. The output signals are ordered from top to
bottom output port.

The Demux block operates in either vector mode or bus selection mode, depending
on whether you selected the Bus selection mode parameter

3. Types of Switches in Simulink?


Switch: The Switch block passes through the first input or the third input based on
the value of the second input. The first and third inputs are called data inputs. The
second input is called the control input.
Multiport Switch: The Multiport Switch block determines which of several inputs to
the block passes to the output. The first input is the control input and the remaining
inputs are the data inputs. The value of the control input determines which data
input passes to the output.

4. What is meant by merge block?


Combine multiple signals into single signal. The Merge block combines its inputs
into a single output line whose value at any time is equal to the most recently
computed output of its driving blocks. You can specify any number of inputs by
setting the block's Number of inputs parameter

When you use the Merge block, follow these guidelines:

 Always use conditionally-executed subsystems to drive Merge blocks.


 Write your control logic to ensure that at most one of the driving conditionally-
executed subsystems executes at any time step.
 Do not connect more than one input of a Merge block to the same conditionally-
executed subsystem.
 Always connect a Merge block to at least two input signals.
 Ensure that all input signals have the same sample time.
5. What is meant by Zero cross detection?

The zero-crossing function passes through zero from a positive or negative value
when the corresponding discontinuity occurs. At the end of each simulation step,
Simulink asks each block that has registered zero-crossing variables to update the
variables. Usually this technique improves simulation run time, but it can cause some
simulations to halt before the intended completion time.

6. What is algebraic loop error

When the input is depending on output of some other block which will be
executed later time, then algebraic loop error will occur.

7. How to avoid algebraic loop?

By adding Unit delay block or Memory block


8. What is meant by MAAB?

Mathworks Automotive Advisory Board (MAAB). MAAB meetings now involve


many of the major automotive OEMs and suppliers, and focus on the usage and
enhancements of Mathworks controls, simulation, and code generation products
including Simulink, State flow, and Embedded Coder

9. When we go to Simulink and State flow

If the function primarily involves complicated logical operations, use State flow
diagrams.

 State flow should be used to implement modal logic – where the control function
to be performed at the current time depends on a combination of past and
present logical conditions.

If the function primarily involves numerical operations, use Simulink features.

Note:

 If the primary nature of the function is logical, but some simple numerical
calculations are done to support the logic, implement the simple numerical
functions using the State flow action language.
 If the primary nature of the function is numeric, but some simple logical
operations are done to support the arithmetic, implement the simple logical
functions with Simulink blocks.
 If the primary nature of the function is logical, and some complicated numerical
calculations must be done to support the logic, use a Simulink subsystem to
implement the numerical calculations. The State flow software should invoke the
execution of this subsystem, using a function-call.
10. Tell me which are the mandatory for MAAB?

Block Resizing: - All blocks in a model must be sized such that their icon is completely
visible and recognizable. In particular, any text displayed (for example, tunable
parameters, filenames, or equations) in the icon must be readable.
Unconnected signals, block inputs and block outputs

A system must not have any:

 Unconnected subsystem or basic block input.


 Unconnected subsystem or basic block outputs
 Unconnected signal lines

In addition:

 An otherwise unconnected input should be connected to a ground block


 An otherwise unconnected output should be connected to a terminator block

Prohibited Simulink standard blocks inside controllers

 Control algorithm models must be designed from discrete blocks.


 The Mathworks “Simulink Block Data Type Support” table provides a list of
blocks that support production code generation.
 Use blocks that are listed as “Code Generation Support”.
 Do not use blocks that are listed as “Not recommended for production code” –
see footnote 4 in the table.
 Such as, Sinewave, Constant, Manual Switch, Pulse generator Random Generator
11. Draw the model for this PID Equations
12. What is meant by Merge block

Combine multiple signals into single signal. The Merge block combines its inputs
into a single output line whose value at any time is equal to the most recently computed
output of its driving blocks. You can specify any number of inputs by setting the block's
Number of inputs parameter.

Guidelines for Using the Merge Block

When you use the Merge block, follow these guidelines:

 Always use conditionally-executed subsystems to drive Merge blocks.


 Do not connect more than one input of a Merge block to the same conditionally-
executed subsystem.
 Always connect a Merge block to at least two input signals.
13. Define Simulink

Simulink is an environment for simulation and model-based design for dynamic


and embedded systems. It provides an interactive graphical environment and a
customizable set of block libraries that let you design, simulate, implement, and test a
variety of time-varying systems, including communications, controls, signal processing,
video processing, and image processing.

Simulink offers:

 A quick way of develop your model in contrast to text based-programming


language such as e.g., C.
 Simulink has integrated solvers. In text based-programming language such as
e.g., C you need to write your own solver.
14. MIL, SIL, PIL, & HIL

MIL
 Models runs in a virtual environment
 Functional models – at the system level
 Implementation models – at an individual module and a whole system levels

SIL

 Software runs in virtual environment without hardware

PIL

 Software runs on a target processor or an emulator, but with a proprietary


hardware (ECU)

HIL

 Final ECU with simulated environment


15. Enabled Subsystems

Enabled subsystems are subsystems that execute at each simulation step for
which the control signal has a positive value.

An enabled subsystem has a single control input, which can be a scalar or a vector.

 If the input is a scalar, the subsystem executes if the input value is greater than
zero.
 If the input is a vector, the subsystem executes if any one of the vector elements
is greater than zero.

States when enabling parameter

 Choose held to cause the states to maintain their most recent values.
 Choose reset to cause the states to revert to their initial conditions
16. Triggered Subsystems

Triggered subsystems are subsystems that execute each time a trigger event occurs. A
triggered subsystem has a single control input, called the trigger input that determines
whether the subsystem executes. You can choose from three types of trigger events to
force a triggered subsystem to begin execution:

 rising triggers execution of the subsystem when the control signal rises from a
negative or zero value to a positive value (or zero if the initial value is negative).
 falling triggers execution of the subsystem when the control signal falls from a
positive or a zero value to a negative value (or zero if the initial value is positive).
 either triggers execution of the subsystem when the signal is either rising or
falling.
17. What is meant by Subsystem?

Subsystems allow you to create a hierarchical model comprising many layers. A


subsystem is a set of blocks that you replace with a single Subsystem block. As your model
increases in size and complexity, you can simplify it by grouping blocks into subsystems.

18. What is meant Variant Subsystem?


 Variant subsystems provide multiple implementations for a subsystem where
only one implementation is active during simulation.
 The Variant Subsystem block includes multiple child subsystems, where only one
subsystem is active during simulation.
 You can programmatically swap out the active implementation with another
implementation without modifying the model.
 The Variant Subsystem block can include Inport, Outport, and Connection Port
blocks. There are no drawn connections inside the Variant Subsystem block.
 Each child subsystem is associated with a variant control, which is created in the
base workspace. The variant control that evaluates to true, determines the
active variant.
19. What is solver and types of Solver?

A solver is a component of the Simulink software. The Simulink product provides


an extensive library of solvers, each of which determines the time of the next simulation
step and applies a numerical method to solve the set of ordinary differential equations
that represent the model.

Both fixed-step and variable-step solvers compute the next simulation time as the
sum of the current simulation time. It is known as step size

 Variable step solver


 Fixed step solver

Variable-step solvers: solve the model at, the step size can vary from step to step,
depending on the model dynamics, reducing the step size to increase accuracy

Fixed-step solvers: solve the model at regular time intervals from the beginning to the
end of the simulation. Generally, decreasing the step size increases the accuracy of the
results while increasing the time required to simulate the system.

20. What is meant by step size?

It computes the next simulation time as the sum of the current simulation time and a
quantity known as the step size.
21. How you will choose the solver?

If you plan to generate code from your model and run the code on a real-time
computer system, choose a fixed-step solver to simulate the model because you cannot
map the variable-step size to the real-time clock.

If you do not plan to deploy your model as generated code, the choice between
a variable-step and a fixed-step solver depends on the dynamics of your model. A
variable-step solver might shorten the simulation time of your model significantly

22. How to import and export data in Simulink & Matlab?

In Matlab, we can import data from xlsx, xml, text, image, and video with
respective import, export functions.

In Simulink, we can import data from xlsx and text files with help of Signal
builders. Also using from workspace & from file blocks.

23. How to generate the code?


 Develop the Model according to the specifications
 Create Subsystems and convert into atomic Systems.
 Go to Settings and change the solver options to Fixed Step Solver
 Select the Generic Target and build the Model
24. What do you know about Black box and white box testing?

Black box Testing: Black Box Testing is a software testing method in which the
internal structure/ design/ model/implementation of the Product being tested is NOT
known to the tester.

White box Testing: (Transparent Testing): It is opposite to black box where every
structure of the product should be known to the tester. Unit, Integration and System
Level testing can be performed through this process

 Unit testing
 Integration testing
 System testing
 Regression testing
25. What is advantage of m files over Simulink/state flow?

M scripting allows us to define and design much more complex models like
BLDC/SRM motor with user defined specifications unlike Simulink which are predefined.

26. How to transfer the data from one subsystem to another executing at different sample
times?
Using Rate Transition Block. The Rate Transition block transfers data from the output
of a block operating at one rate to the input of a block operating at a different rate. Use
the block parameters to trade data integrity and deterministic transfer for faster
response or lower memory requirements

27. What are Simulink commands in Matlab?

 new_system,  add_system  add_line


 open_system  delete_system  delete_line
 close_system  replace_system  find_system
 load_system  set_param  gcb, gcs
 save_system  get_param  bdroot

28. What is the command for Auto Code generation in Matlab?

open_system(‘model_name’); or load_system(‘model_name’);

rtwbuild(‘model_name’);

close_system(‘model_name’);

exit;

MATLAB State flow Interview Questions

1. What is meant by State?

A state describes an operating mode of a reactive system. In a State flow chart,


states are used for sequential design to create state transition diagrams.

States can be active or inactive. The activity or inactivity of a state can change
depending on events and conditions.

2. What is meant by State Decomposition?

Every state (or chart) has a decomposition that dictates what type of substates the
state (or chart) can contain. All substates of a superstate must be of the same type as
the superstate decomposition. State decomposition can be Exclusive (OR) or parallel
(AND).

Exclusive OR: Substates with solid borders indicate EXCLUSIVE OR state decomposition.
Use this decomposition to describe operating modes that are mutually exclusive. When
a state has exclusive OR decomposition, only one substate can be active at a time.
Parallel AND: Substates with dashed borders indicate PARALLEL AND decomposition.
Use this decomposition to describe concurrent operating modes. When a state has
parallel (AND) decomposition, all substates are active at the same time.

3. What are the State Action?


 Entry
 During
 Exit
4. What Is a Transition?

A transition is a line with an arrowhead that links one graphical object to


another. In most cases, a transition represents the passage of the system from one
mode (state) object to another. A transition typically connects a source and a
destination object. The source object is where the transition begins and the destination
object is where the transition ends.

5. What Is a Default Transition?

A default transition has a destination but no source object. A default transition


specifies which exclusive (OR) state to enter when there is ambiguity among two or
more neighboring exclusive (OR) states.

6. Transition Action Types?

Transitions can have different action types, which include event or message triggers,
conditions, condition actions, and transition actions. The action types follow the label
notation with this general format:

event_or_message trigger[condition]{condition_action}/{transition_action}

7. What is meant by Inner Transition?

An inner transition is a transition that does not exit the source state. Inner
transitions are powerful when defined for superstates with exclusive (OR)
decomposition

8. What Is a History Junction?

A history junction represents historical decision points in the Stateflow chart. The
decision points are based on historical data relative to state activity. Placing a history
junction in a superstate indicates that historical state activity information is used to
determine the next state to become active. The history junction applies only to the level
of the hierarchy in which it appears
9. What Is a Connective Junction?

The connective junction enables representation of different possible transition paths


for a single transition.

 Transitions from a common source to multiple destinations


 Transitions from multiple sources to a common destination
 Transitions from a source to a destination based on common events

10. What Is Temporal Logic?

Temporal logic controls execution of a chart in terms of time. In state actions and
transitions, you can use two types of temporal logic: event-based and absolute-time. To
operate on these recurring events or simulation time, you use built-in functions called
temporal logic operators.

 Event-based temporal logic: keeps track of recurring events, and


 Absolute-time temporal logic: defines time periods based on the simulation time
of your chart.
11. What Is a Finite State Machine?

Stateflow charts can contain sequential decision logic based on state machines. A
finite state machine is a representation of an event-driven (reactive) system. In an
event-driven system, the system makes a transition from one state (mode) to another, if
the condition defining the change is true.

For example, you can use a state machine to represent the automatic transmission
of a car. The transmission has these operating states: park, reverse, neutral, drive, and
low. As the driver shifts from one position to another, the system makes a transition
from one state to another, for example, from park to reverse.

12. What is the Stateflow Chart?

A Stateflow chart can contain sequential and combinatorial logic in the form of state
transition diagrams, flow charts, state transition tables, and truth tables. A state
transition diagram is a graphical representation of a finite state machine.

13. Define Time Delays with Temporal Logic

Use one of the keywords sec, msec, or usec to define simulation time in seconds,
milliseconds, or microseconds that have elapsed since activation of a state. These
keywords are valid only in state actions and in transitions that originate from states.

14. What is the difference Between Flow Charts and State Transition Diagrams?
A flow chart is used for combinatorial design. It is a stateless flow chart because it
cannot maintain its active state between updates. As a result, a flow chart always begins
executing from a default transition and ends at a terminating junction (a junction that
has no valid outgoing transitions).

By contrast, a state transition diagram is used for sequential design. It stores its
current state in memory to preserve local data and activity between updates. As a
result, state diagrams can begin executing where they left off in the previous time step,
making them suitable for modeling reactive or supervisory systems that depend on
history. In these kinds of systems, the current result depends on a previous result.

You might also like