0% found this document useful (0 votes)
10 views

Assignment for IMI (1)

Uploaded by

Divya g
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views

Assignment for IMI (1)

Uploaded by

Divya g
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 61

Questions on Embedded C:

1. Explain about storage class and type qualifiers:

Storage Classes are used to describe the features of a variable/function. These


features basically include the scope, visibility and life-time which help us to trace
the existence of a particular variable during the runtime of a program.

Type qualifiers are basically the keywords that are used to modify the properties of
the existing variables.

● const
● volatile
● restrict

2. What is enum and typedef


An enumeration, or Enum , is a symbolic name for a set of values. Enumerations
are treated as data types, and you can use them to create sets of constants for use
with variables and properties.

1
The typedef keyword is to allow users to provide alternative names for the
primitive (e.g., int) and user-defined (e.g struct) data types.This keyword adds a
Ṁ<M
new name for some existing data type but does not create a new type.

3. Difference between Microprocessor and Microcontroller

2
4. Explain the purpose of getchar and putchar

● putchar() function is a file handling function in C programming


language which is used to write a character on standard

3
output/screen. getchar() function is used to get/read a character
from keyboard input.
● The getchar() function is equivalent to a call to getc(stdin). It
reads the next character from stdin which is usually the
keyboard.
● putchar() is a function in the C programming language that
writes a single character to the standard output stream, stdout.
Its prototype is as follows: int putchar (int character) The
character to be printed is fed into the function as an argument,
and if the writing is successful, the argument character is
returned.

5. What is typecasting?
● Type Casting is basically a process in C in which we change a
variable belonging to one data type to another one. In type
casting, the compiler automatically changes one data type to
another one depending on what we want the program to do.
● For instance, if you assign an integer value to a floating-point
variable, the compiler will convert the int to a float.
● Here is the syntax of explicit type casting in C language,

(type) expression

6. What are embedded systems? Explain along with its types.


● Embedded systems comprise hardware and software that work
together to perform specific tasks. They rely on
microprocessors, microcontrollers, memory, input/output
communication interfaces, and a power supply to function

4
7. Explain what is interrupt latency and ISR? How can you reduce
the interrupt latency?
● Interrupt latency, also called interrupt response time, is the
length of time that it takes for a computer interrupt to be acted
on after it has been generated.
● The term interrupt latency refers to the delay from the start of
the interrupt request to the start of interrupt handler execution.
● An interrupt service routine (ISR) is a software routine that
hardware invokes in response to an interrupt. ISR examines an
interrupt and determines how to handle it, executes the
handling, and then returns a logical interrupt value. If no further
handling is required the ISR notifies the kernel with a return
value.
● You can minimize interrupt latency by making your interrupt
routine as short as possible if your hardware does not allow
interrupt priorities because in this case a started interrupt
routine can not be interrupted by another (higher priority)
interrupt.
● To minimize interrupt latency, the processor abandons any
divide instruction to take any pending interrupt. On return from
the interrupt handler, the processor restarts the divide

5
instruction from the beginning. The processor implements the
Interruptible-continuable Instruction field.

8. Explain OSI layers

Group Layer Layer Description


Number Name

Top 7 Applicat Provide a user interface for sending and receiving


Layers ion data

6 Presenta Encrypt, format, and compress data for


tion transmission

5 Session Initiate and terminate a session with the remote


system

Bottom 4 Transpo Break the data stream into smaller segments and
Layers rt provide reliable and unreliable data delivery

3 Network Provide logical addressing

2 Data Prepare data for transmission


Link

1 Physical Move data between devices

9. Define array, structure and union


array:An array is defined as the collection of similar types of data
items stored at contiguous memory locations. Arrays are the derived

6
data type in C programming language which can store the primitive
type of data such as int, char, double, float, etc.
structure:Structure in c is a user-defined data type that enables us to
store the collection of different data types.You can create a collection
of all related information with the help of structures. Before using the
structure variables, you will have to access the members of the
structure.
Union:A union is a special data type available in C that allows to
store different data types in the same memory location. You can
define a union with many members, but only one member can contain
a value at any given time. Unions provide an efficient way of using
the same memory location for multiple-purpose.

10.Differentiate malloc and calloc


malloc() function creates a single block of memory of a specific size.
calloc() function assigns multiple blocks of memory to a single
variable.

11.Explain bitwise operators and ternary operator

Bitwise AND Operator

7
Bitwise "AND" operator will take bit by bit from two operands and generate the
AND output of those two bits. For example, (4&5) generates output as 4.

0000 0100 (4)

0000 0101 (5)

-------------

0000 0100 (4)

Bitwise OR Operator

Bitwise OR operator will take bit by bit from two operands and generate the OR
output of those two bits. For example, (5|6) will generate output: 7

0000 0101 (5)

0000 0110 (6)

-------------

0000 0111 (7)

Bitwise XOR Operator

Bitwise XOR operator will take bit by bit from two operands and generate the
XOR output of those two bits. For example, (5|6) will generate output: 3

0000 0101 (5)

0000 0110 (6)

8
-------------

0000 0011 (3)

One's Compliment Operator/Bitwise NOT

Unlike other bitwise operators, One's complement (~) is a unary operator. One's
complement operator will invert each bit of the operand (1 will be changed to 0
and Vice versa). For example, '~5' will produce output '-6' as given below

0000 0101 (5)

-------------

1111 1010 (This is -6 in 2's complement form)

Right Shit Operator

The right shift (>>) operator shifts each bit of its first operand to right by n times
where n is the second operand. For example, If a is 75 (binary: 0100 1011) and we
perform a right shift operation on 'b' like b >> 3, then the output will be 9.

b = 0100 1011 -> Initial state (75)

b = 0010 0101 -> After one bit right shift (37)

b = 0001 0010 -> After two bit right shift (18)

Left Shift Operator

The left shift (<<) operator shifts each bit of its first operand to left by n times
where n is the second operand. For example, consider 'a' is 7, then expression a <<
7 will produce output 56. Let's take a look how this expression is evaluated

a = 0000 0111 -> Initial state (7)

9
a = 0000 1110 -> After one bit left shift (14)

a = 0001 1100 -> After two bit left shift (28)

Ternary Operator

We use the ternary operator in C to run one code when the condition is true and
another code when the condition is false.

The ternary operator take three arguments:

1. The first is a comparison argument


2. The second is the result upon a true comparison
3. The third is the result upon a false comparison

12.What is FSM?Explain along with its types.


An FSM is defined by a list of its states, its initial state, and the inputs
that trigger each transition. Finite-state machines are of two types—
deterministic finite-state machines and non-deterministic finite-state
machines.

A turnstile, used to control access to subways and amusement park


rides, is a gate with three rotating arms at waist height, one across the
entryway. Initially the arms are locked, blocking the entry, preventing
patrons from passing through. Depositing a coin or token in a slot on
the turnstile unlocks the arms, allowing a single customer to push
through. After the customer passes through, the arms are locked again
until another coin is inserted.

State Diagram:

10
State Table:

Current Inp Next Output


State ut State

Locked coin Unlocke Unlocks the turnstile so that the customer can
d push through.

push Locked None

Unlocked coin Unlocke None


d

push Locked When the customer has pushed through, locks


the turnstile.

Types of Finite State Machine

The finite state machines are classified into two types such as Mealy state machine
and Moore state machine.

Mealy State Machine

11
When the outputs depend on the current inputs as well as states, then the FSM can

be named to be a mealy state machine. The following diagram is the mealy state

machine block diagram. The mealy state machine block diagram consists of two

parts namely combinational logic as well as memory. The memory in the machine

can be used to provide some of the previous outputs as combinational logic inputs.

Moore State Machine

When the outputs depend on current states then the FSM can be named as Moore

state machine. The Moore state machine’s block diagram is shown below. The

Moore state machine block diagram consists of two parts namely combinational

logic as well as memory.

13.Explain the difference between mutexes and semaphores?

14. Define functions and preprocessors..

12
Functions:A function is a group of statements that together perform a
task. Every C program has at least one function, which is main(), and
all the most trivial programs can define additional functions. You can
divide up your code into separate functions.
Preprocessors:he C preprocessor is a macro preprocessor (allows you
to define macros) that transforms your program before it is compiled.
These transformations can be the inclusion of header files, macro
expansions, etc

15.What is buffer overflow in C?


A buffer overflow occurs when the size of information written to a
memory location exceeds what it was allocated. This can cause data
corruption, program crashes, or even the execution of malicious code

16.What is the purpose of bootloader in Embedded systems?


Bootloader is the first piece of firmware which gets executed once the
Embedded System is turned-on/reset. The primary objective of the
Bootloader is to initialize the Embedded System and provide control
to the Application/RTOS. The other objective of the Bootloader is
also to support the data loading feature.

17.Why is DSP required?


C compiler translates high-level C programs into machine language
that can be executed by computers or DSP proces- sors such as the
TMS320C55x. The fact that C compilers are available for a wide
range of computer platforms and DSP processors makes C
programming the most portable software for DSP applications.

18.What is the difference between Break and Continue


The primary difference between break and continue statement in C is
that the break statement leads to an immediate exit of the innermost
switch or enclosing loop. On the other hand, the continue statement
begins the next iteration of the while, enclosing for, or do loop.

13
19.What is structure padding and bit fields
● Structure padding is a concept in C that adds the one or more
empty bytes between the memory addresses to align the data in
memory.
● A bit field is a data structure that allows the programmer to
allocate memory to structures and unions in bits in order to
utilize computer memory in an efficient manner.

20.Difference between Switch Case and If else statement


In the case of 'if-else' statement, either the 'if' block or the 'else' block
will be executed based on the condition. In the case of the 'switch'
statement, one case after another will be executed until the break
keyword is not found, or the default statement is executed.

21.What do you mean by Dangling pointer?


● A dangling pointer is a pointer that occurs at the time when the
object is de-allocated from memory without modifying the
value of the pointer.
● Sometimes the programmer fails to initialize the pointer with a
valid address, then this type of initialized pointer is known as a
dangling pointer in C

22.What are the basic Data Types supported in C Programming


Language?

14
23.What is a volatile qualifier in C language?
● The volatile qualifier is applied to a variable when we declare
it. It is used to tell the compiler, that the value may change at
any time.
● The volatile keyword is intended to prevent the compiler from
applying any optimizations on objects that can change in ways
that cannot be determined by the compiler.

24.What is a far pointer?


● Far pointer is a 32-bit pointer, can access information which is
outside the computer memory in a given segment.
● For example, in an Intel 8086, as well as in later processors
running 16-bit code, a far pointer has two parts: a 16-bit
segment value, and a 16-bit offset value. A linear address is

15
obtained by shifting the binary segment value four times to the
left, and then adding the offset value.

25.What is the return type of a fopen function


Ans: The fopen function returns a pointer to a FILE object associated
with the named file. If the file cannot be opened, a NULL value is
returned.
26.What is the use of return statement in a function, how many
values a return statement can return from a function
Ans: A return statement ends the execution of a function, and
returns control to the calling function. Execution resumes in the
calling function at the point immediately following the call. A return
statement can return one value to the calling function.
27.What is a void pointer?
The void pointer in C is a pointer that is not associated with any data
types. It points to some data location in the storage. This means that it
points to the address of variables. It is also called the general purpose
pointer. In C, malloc() and calloc() functions return void * or generic
pointers.

28.What is stack pointer and program counter


Stack pointer:A stack pointer is a small register that stores the
address of the last program request in a stack. A stack is a specialized
buffer which stores data from the top down. As new requests come in,
they "push down" the older ones.
Program counter:The Program Counter is a 16- or 32-bit register
which contains the address of the next instruction to be executed. The
PC automatically increments to the next sequential memory location
every time an instruction is fetched.

29.What is the output of the following program and explain in detail


about the logic of the code

16
#include<stdio.h>
int a,b,c=0;
void fun(void);
int main()
{
static int a=1;
fun();
a+=1;
fun();
printf(“\n In main function %d %d”, a,b);
}
void fun(void)
{
static int a=2;
int b=1;
a+=++b;
printf(“\n In user defined function %d %d”, a,b);
}
Ans: 4 2 6 2 2 0

Inside fun, static a is initialized to 2, b is initialized to 1, a+=++b


results in a value to 4 and b as 2. In second function call of fun function, static a is
maintained with older value of 4, where as b is reinitialized to 1, hence a+=++b
results in a value to 6 and b value to 2
Inside main, static a is initialized to 1, incremented by 1 and b not
initialized with any values, so default value of global variable b takes 0, thus a and
b is 2 and 0 respectively inside main function
30.What is the usage/effect of left shift and right shift operations in
binary numbers
● The bitwise shift operators move the bit values of a binary
object. The left operand specifies the value to be shifted. The
right operand specifies the number of positions that the bits in
the value are to be shifted.

17
● Shifting left by n bits on a signed or unsigned binary number
has the effect of multiplying it by 2n. Shifting right by n bits on
a two's complement signed binary number has the effect of
dividing it by 2n, but it always rounds down (towards negative
infinity).

31.Can a C program be compiled or executed in the absence of a


main()?
Ans: The program will be compiled but will not be executed. To
execute any C program, main() is required.By default, gcc (and most
C compilers) compile and link to a standalone executable. The main()
function is required so that the startup code knows where execution of
your code should start.

32.What is an inline function


● An inline function is one for which the compiler copies the
code from the function definition directly into the code of the
calling function rather than creating a separate set of
instructions in memory.
● In an inline function, a function call is replaced by the actual
program code. Most of the Inline functions are used for small
computations. They are not suitable for large computing. An
inline function is similar to a normal function. The only
difference is that we place a keyword inline before the function
name.

33.What are the different steps in the compilation process? Explain


in brief.

18
Four Steps of Compilation: preprocessing, compiling, assembly,
linking.

Preprocessing:

Preprocessing is the first step. The preprocessor obeys commands that begin with #
(known as directives) by:

● removing comments
● expanding macros
● expanding included files

If you included a header file such as #include <stdio.h>, it will look for the stdio.h
file and copy the header file into the source code file.

The preprocessor also generates macro code and replaces symbolic constants
defined using #define with their values.

Compiling:Compiling is the second step. It takes the output of the preprocessor and

generates assembly language, an intermediate human readable language, specific to the

target processor.

Assembly:Assembly is the third step of compilation. The assembler will convert the

assembly code into pure binary code or machine code (zeros and ones). This code is also

known as object code.

19
Linking:Linking is the final step of compilation. The linker merges all the object code

from multiple modules into a single one. If we are using a function from libraries, linker

will link our code with that library function code.

34.Describe the difference between = and == symbols in C


programming?
First of all = is a assignment operator and == is a comparison
operator.
= operator is used to assign value to a variable and == operator is used
to compare two variable or constants.

35. Describe the header file and its usage in C programming?


A header file is a file with extension . h which contains C function
declarations and macro definitions to be shared between several
source files.
You request the use of a header file in your program by including it,
with the C preprocessing directive ' #include '.

36.What is a nested loop?


Nested loop means a loop statement inside another loop statement.
That is why nested loops are also called as “loop inside loop“. Syntax
for Nested For loop:
for ( initialization; condition; increment )
{
for ( initialization; condition; increment )
{
// statement of inside loop
}
// statement of outer loop
}

20
37.What is the general form of function in C?

A function is a group of statements that together perform a task. Every


C program has at least one function, which is main(), and all the most
trivial programs can define additional functions. You can divide up
your code into separate functions.

38.What is a pointer on a pointer in C programming language?

A pointer to a pointer is a form of multiple indirection, or a chain of


pointers. Normally, a pointer contains the address of a variable. When
we define a pointer to a pointer, the first pointer contains the address
of the second pointer, which points to the location that contains the
actual value

39.Explain the use of function toupper() with an example code?

The toupper() function converts a lowercase alphabet to an uppercase


alphabet.
#include <ctype.h>
#include <stdio.h>

int main()
{
char ch;

ch = 'g';
printf("%c in uppercase is represented as %c",ch, toupper(ch));

21
return 0;
}

40.What are the modifiers available in the C programming


language?

There are five data type modifiers in C Programming Language:

Long,short,signed and unsigned

41.Is that possible to store 32768 in an int data type variable?

No. "int" data type is capable of storing values from -32768 to 32767.
To store 32768, you can use "long int" instead.

42.What is the explanation for modular programming?

Modular programming (also referred to as modular architecture) is a


general programming concept. It involves separating a program's
functions into independent pieces or building blocks, each containing
all the parts needed to execute a single aspect of the functionality.

43.What are the ways to a null pointer that can be used in the C
programming language?
● Make a habit of assigning the value to a pointer before using it.
Don’t use pointer before initializing it.
● If you don’t have a valid memory address to store in a pointer
variable, just initialize a pointer to NULL.

22
● Before using a pointer in any of function code, check if it has
not a NULL value.

44.Differentiate Source Codes from Object Codes

45. What is the use of a ‘\0’ character?

It is used to show that the string is completed.it marks the end of the
string. it is mainly used in string type.by default string contain '\0\
character means it shows the end of the character in string. end of the
array contains ''\0' to stop the array memory allocation for string
name.

46.Compare and contrast compilers from interpreters.

23
47. When used as aWhen is the “void” keyword used in a function?

48. function return type, the void keyword specifies that the function
doesn't return a value. When used for a function's parameter list, void
specifies that the function takes no parameters. When used in the
declaration of a pointer, void specifies that the pointer is "universal."

49.What is FIFO and binary trees?

FIFO is an abbreviation for first in, first out. It is a method for


handling data structures where the first element is processed first and
the newest element is processed last.
A binary tree is a tree data structure in which each node has at most
two children, which are referred to as the left child and the right child.

24
50.What is the difference between the expression “++a” and “a++”?

++a is the prefix increment operator whose value is increased by 1


first then the operation is performed and a++ is the postfix increment
operator whose value increases by 1 after the operation is performed.

51.What are the advantages and disadvantages of a heap?

● Heap helps you to find the greatest and minimum number.


Garbage collection runs on the heap memory to free the
memory used by the object. Heap method also used in the
Priority Queue. It allows you to access variables globally.
● Disadvantage of using Heap is storing data on Heap is slower
than it would take when using the stack

Questions on Software V and V

52.Differentiate between verification and validation?

25
53.Define the term Testing.

Software testing is the process of evaluating and verifying that a


software product or application does what it is supposed to do.
The benefits of testing include preventing bugs, reducing development
costs and improving performance.

26
54.Define Test Cases.

A test case is a document, which has a set of test data, preconditions,


expected results and postconditions, developed for a particular test
scenario in order to verify compliance against a specific requirement.

55.Compare black box and white box testing.

56.Define Error Guessing.

Error guessing is an experience based technique where the test


analyst uses his / her experience to guess the problematic areas of the
application.

57.What are the factors affecting less than 100% degree of coverage?

27
The nature of the unit Some statements/branches may not be
reachable. The unit may be simple, and not mission, or safety, critical,
and so complete coverage is thought to be unnecessary.

58.Define integration Test.

Integration Testing is a type of software testing, which is performed


on software to determine the flow between two or more modules by
combining them. Integration testing makes sure that the interactions
between different components of the software is completed smoothly
without any complication.

59.Define test Harness.

In software development, a test harness is a collection of software


and test data used by developers to unit test software models
during development. A test harness will specifically refer to test
drivers and stubs, which are programs that interact with the software
being tested.

60.List the Test plan components.

28
61.What is SDLC?

Software Development Life Cycle (SDLC) is a process used by the


software industry to design, develop and test high quality
softwares. The SDLC aims to produce a high-quality software that
meets or exceeds customer expectations, reaches completion within
time and cost estimates.

29
62. Explain the Waterfall model , V model and agile model in detail.

Waterfall Model:
Different phases Activities performed in each stage

Requirement
Gathering stage ● During this phase, detailed requirements of the
software system to be developed are gathered from
client
Design Stage
● Plan the programming language, for Example Java,
PHP, .net
● or database like Oracle, MySQL, etc.
● Or other high-level technical details of the project
Built Stage
● After design stage, it is built stage, that is nothing but
coding the software
Test Stage
● In this phase, you test the software to verify that it is
built as per the specifications given by the client.
Deployment stage
● Deploy the application in the respective environment

Maintenance stage
● Once your system is ready to use, you may later
require change the code as per customer request

V-Model:
The V-model is an SDLC model where execution of processes happens in a
sequential manner in a V-shape. It is also known as the Verification and Validation
model.

30
The V-Model is an extension of the waterfall model and is based on the association
of a testing phase for each corresponding development stage. This means that for
every single phase in the development cycle, there is a directly associated testing
phase. This is a highly-disciplined model and the next phase starts only after
completion of the previous phase.

Agile Model:
● Agile SDLC model is a combination of iterative and
incremental process models with focus on process adaptability
and customer satisfaction by rapid delivery of working software
products.
● Agile Methods break the product into small
incremental builds. These builds are provided in
iterations. Each iteration typically lasts from about
one to three weeks. Every iteration involves cross
functional teams working simultaneously on
various areas like −
● Planning
● Requirements Analysis
● Design
● Coding
● Unit Testing and
● Acceptance Testing.

31
63.What is the LDRA tool?

The LDRA tool suite is a flexible platform for producing safety, security, and
mission-critical software in an accelerated, cost effective and requirements driven
process.

Liverpool Data Research Associates (LDRA) is a provider of software analysis,


and test and requirements traceability tools for the Public and Private sectors and a
pioneer in static and dynamic software analysis.

64.What is TBrun?

TBrun® is a component of the LDRA tool suite®. It is a unit/integration test tool,


providing a complete verification environment for the automated generation and
management of test harnesses and unit/integration tests.

32
65.Explain Dynamic coverage analysis

● Dynamic Testing is a software testing method used to test the


dynamic behaviour of software code. The main purpose of
dynamic testing is to test software behaviour with dynamic
variables or variables which are not constant and finding weak
areas in software runtime environment. The code must be
executed in order to test the dynamic behavior.
● The main aim of the Dynamic tests is to ensure that software
works properly during and after the installation of the software
ensuring a stable application without any major flaws( this
statement is made because no software is error free, testing only
can show presence of defects and not absence)
● The main purpose of the dynamic test is to ensure consistency
to the software

66. What is ASPICE?

Automotive Software Performance Improvement and Capability


dEtermination (ASPICE) as a standard provides the framework for
defining, implementing, and evaluating the process required for
system development focused on software and system parts in the
automotive industry.

67.List the Core components of LDRA Testsuite

The core components of the LDRA tool suite are:


LDRA Testbed
TBvision
TBrun
TBmanager.

33
Questions on AVR and bare metal programming

68.What is bare-metal programming?

Bare-metal programming means writing an application directly on


your hardware without using an external application programming
interface i.e. without any operating system.
Bare-metal applications tend to be written at a low-level, where the
application developer is directly accessing registers using their own
software.

69. What is the difference between I2C and SPI

34
70. State the registers used in Timers/Counters of AVR
TCNTn: Timer/counter Register is the register that counts up (or
down). OCRn is the Output Compare Register for timer/counter n.

TIFR: Timer Interrupt Flag (TIFR) Register are used to control which
interrupts are "valid" by setting their bits in TIMSK and to determine
which interrupts are currently pending (TIFR).

TCCR: TIMER /COUNTER control register is used to set the timer


mode, prescaler and other options.

OCRn is the Output Compare Register for timer/counter n. There are


two of these, A and B. When the TCNTn register matches the OCR(A
or B)n register a number of things can happen, depending on how you
programmed the device.

TIMSKn is the interrupt mask register for timer/counter n. If a bit


corresponding to an interrupt is set in here, that interrupt is turned on.

Timer/Counter Overflow Flag. The bit TOV0 is set (one) when an


overflow occurs in Timer/Counter0. TOV0 is cleared by writing a
logic one to the flag. Alternatively, TOV0 is cleared by hardware
when executing the corresponding interrupt handling vector.

71. List the features of AVR

● Multifunction
● Multiple internal oscillators
● Flash memory up to 256 KB
● Internal data EEPROM up to 4 KB

35
● Internal SRAM up to 16 KB
● Two timers are 8 bit, and one timer is 16 bit

72. Explain self programming

● Self is an object-oriented programming language based on the


concept of prototypes.
● Self is an object-oriented programming language based on the
concept of prototypes. Self began as a dialect of Smalltalk,
being dynamically typed and using just-in-time compilation
(JIT) as well as the prototype-based approach to objects: it was
first used as an experimental test system for language design in
the 1980s and 1990s. In 2006, Self was still being developed as
part of the Klein project, which was a Self virtual machine
written fully in Self. The latest version is 2017.

73. What is USART?

● The USART stands for universal synchronous and asynchronous receiver


and transmitter. It is a serial communication of two protocols. This protocol
is used for transmitting and receiving the data bit by bit with respect to clock
pulses on a single wire.

74. List the features of A to D converter in AVR.


Use 10-bits output as upper bits or lower bits in ADCH & ADCL.
We can select input channel ADC0 to ADC7 by using these bits.
These bits are also used to select comparator (inbuilt in AVR) inputs
with various gain.

ADC Register.

36
REFS1 REFS0 Vref to
ADC

0 1 AVCC pin
i.e. Vcc 5 V

1 0 Reserved

1 1 Internal 2

75.What is a watchdog timer?

● A watchdog timer (WDT) is a timer that monitors


microcontroller (MCU) programs to see if they are out of
control or have stopped operating. It acts as a “watchdog”
watching over MCU operations. A microcontroller (MCU) is a
compact processor for controlling electronic devices.
● The watchdog timer communicates with the MCU at a set
interval. If the MCU does not output a signal, outputs too many
signals or outputs signals that differ from a predetermined
pattern, the timer determines that the MCU is malfunctioning
and sends a reset signal to the MCU.

76.Explain brown out reset

● A Brown-out Reset (BOR) is a circuit that monitors the VDD


level during operation by comparing it to a fixed threshold
level. When VDD drops below the threshold level, the Brown-
out Reset is activated. When VDD rises again, the controller is
restarted after a specified delay.
● A “brown out” of a microcontroller is a partial and temporary
reduction in the power supply voltage below the level required
for reliable operation.

37
77.What is Framing

Framing is a point-to-point connection between two computers or


devices consisting of a wire in which data is transmitted as a stream of
bits. However, these bits must be framed into discernible blocks of
information. Framing is a function of the data link layer.

78.What do we use to generate waveforms

To generate different Analog waveforms using AVR microcontroller


it is required to interface a DAC that will convert the Digital inputs
given by the microcontroller into corresponding Analog outputs and
thus it generates different analog waveforms. The DAC output is the
current equivalent of digital input.

79.Explain PWM and give some real life examples

● Pulse width modulation (PWM) is a modulation technique that


generates variable-width pulses to represent the amplitude of an
analog input signal. The output switching transistor is on more
of the time for a high-amplitude signal and off more of the time
for a low-amplitude signal.
● All new model iPhone and iPad devices with OLED displays
have PWM

80.What is FPU, why it is needed


● A floating-point unit (FPU, colloquially a math coprocessor) is
a part of a computer system specially designed to carry out
operations on floating-point numbers.

38
● An FPU provides a faster way to handle calculations with
non-integer numbers. Any mathematical operation, such as
addition, subtraction, multiplication, or division can be
performed by either the integer processing unit or the FPU.

81.With a given Frequency of 8MHz, how can we generate a signal of


128KHz. What is primarily used here to generate this kind of
signal in register level

By using Prescalar.

Programming questions:
1. Write a program/logic to print 10 continuously for 100 times. (Assigning
10 directly to a variable is restricted)
Using a number 1, by left shifting it to 1 time, we get the value of 10.
Lets say a=1
a<<1, yields a the value of 10
This we can put it inside a loop and runs for 100 times
#include <stdio.h>
int main(){
int a[10],n,i,j=1;
while(j<101)
{
n=2;
for(i=0;n>0;i++)
{
a[i]=n%2;
n=n/2;
}
printf("\nPrinting %d time ",j);

39
for(i=i-1;i>=0;i--)
{
printf("%d",a[i]);
}
j=j+1;
}
return 0;
}

2. Write a program to print Fibonacci Series


#include<stdio.h>
int main()
{
int n1=0,n2=1,n3,i,number;
printf("Enter the number of elements:");
scanf("%d",&number);
printf("\n%d %d",n1,n2);//printing 0 and 1
for(i=2;i<number;++i)//loop starts from 2 because 0 and 1 are already
printed
{
n3=n1+n2;
printf(" %d",n3);
n1=n2;
n2=n3;
}
return 0;
}

3. Write a program to print prime numbers in a given range of 50 -100


#include <stdio.h>
#include <stdlib.h>

void main()
{
int num1, num2, i, j, flag, temp, count = 0;

40
printf("Enter the value of num1 and num2 \n");
scanf("%d %d", &num1, &num2);
if (num2 < 2)
{
printf("There are no primes upto %d\n", num2);
exit(0);
}
printf("Prime numbers are \n");
temp = num1;
if ( num1 % 2 == 0)
{
num1++;
}
for (i = num1; i <= num2; i = i + 2)
{
flag = 0;
for (j = 2; j <= i / 2; j++)
{
if ((i % j) == 0)
{
flag = 1;
break;
}
}
if (flag == 0)
{
printf("%d\n", i);
count++;
}
}
printf("Number of primes between %d & %d = %d\n", temp, num2,
count);
}

41
4. Write a program to explain the difference between call by value and call
by reference
Call by value:
#include <stdio.h>
void swap(int , int); //prototype of the function
int main()
{
int a = 10;
int b = 20;
printf("Before swapping the values in main a = %d, b = %d\n",a,b); //
printing the value of a and b in main
swap(a,b);
printf("After swapping values in main a = %d, b = %d\n",a,b); // The
value of actual parameters do not change by changing the formal parameters
in call by value, a = 10, b = 20
}
void swap (int a, int b)
{
int temp;
temp = a;
a=b;
b=temp;
printf("After swapping values in function a = %d, b = %d\n",a,b); //
Formal parameters, a = 20, b = 10
}
Call by reference:
#include <stdio.h>
void swap(int *, int *); //prototype of the function
int main()
{
int a = 10;
int b = 20;
printf("Before swapping the values in main a = %d, b = %d\n",a,b); //
printing the value of a and b in main
swap(&a,&b);

42
printf("After swapping values in main a = %d, b = %d\n",a,b); // The
values of actual parameters do change in call by reference, a = 10, b = 20
}
void swap (int *a, int *b)
{
int temp;
temp = *a;
*a=*b;
*b=temp;
printf("After swapping values in function a = %d, b = %d\n",*a,*b); //
Formal parameters, a = 20, b = 10
}

5. Write a program to find total no’s of 1 and 0’s in any binary number.
For example, 10101010 has 4 numbers of 1 and 4 numbers of 0 in it.

#include <stdio.h>

void count1sand0s(int N)
{
// Initialise count variables
int count0s = 0, count1s = 0;

// Iterate through all the bits


while (N > 0)
{

// If current bit is 1
if (N & 1)
{
count1s++;
}

43
// If current bit is 0
else
{
count0s++;
}

N = N >> 1;
}

// Print the count


printf("Count of 0s in N is %d\n", count0s);
printf("Count of 1s in N is %d\n", count1s);
}

int main()
{
// Given Number
int N = 8;

// Function Call
count1sand0s(N);
return 0;
}

6. Write a program to find factorial of any number


Without Recursion:
#include<stdio.h>
int main()
{
int i,fact=1,number;
printf("Enter a number: ");
scanf("%d",&number);
for(i=1;i<=number;i++){
fact=fact*i;
}

44
printf("Factorial of %d is: %d",number,fact);
return 0;
}
With Recursion:
#include<stdio.h>

long factorial(int n)
{
if (n == 0)
return 1;
else
return(n * factorial(n-1));
}
void main()
{
int number;
long fact;
printf("Enter a number: ");
scanf("%d", &number);

fact = factorial(number);
printf("Factorial of %d is %ld\n", number, fact);
return 0;
}

7. Write a program to find the sum of the series 1+11+111+1111+....


int summation(int n)
{
int sum = 0, j = 1;
for (int i = 1; i <= n; i++) {
sum = sum + j;

// Appending a 1 at the end


j = (j * 10) + 1;
}

45
return sum;
}

// Driver Code
int main()
{
int n = 4;
printf("%d", summation(n));
return 0;
}

8. Write a program to find the print odd and even numbers for the given
range of numbers 101-175

#include <stdio.h>
#include <stdlib.h>
int main()
{
int num1, num2,r,i;
printf("Enter the first number for the range: ");
scanf("%d",&num1); //received the number for num1
printf("Enter the second number for the range: ");
scanf("%d",&num2); //received the number for num2
printf("\nDisplay the even numbers between %d and %d are:
",num1,num2);
for(i=num1; i<=num2; i++){
r=i%2;
if(r==0)
printf("\n %d",i);
}
printf("\n\nDisplay the odd numbers between %d and %d are:
",num1,num2);

46
for(i=num1; i<=num2; i++){
r=i%2;
if(r==1)
printf("\n %d",i);
}
getch();
return 0;
}

9. Write a program to print reversing a string without string header file


and reversing a number

#include <stdio.h>
#include <conio.h>

void main(){
char string[20],temp;
int i,length;
printf("Enter String : ");
scanf("%s",string);
length=strlen(string)-1;
for(i=0;i<strlen(string)/2;i++){
temp=string[i];
string[i]=string[length];
string[length--]=temp;
}
printf("\nReverse string :%s",string);
getch();
}

10.Write a logic to find the 2^n for any n number, n=10 (2^10=1024)

#include<stdio.h>

/* Function to calculate a raised to the power y */

47
int power(int a, unsigned int b)
{
if (b == 0)
return 1;
else if (b%2 == 0)
return power(a, b/2)*power(a, b/2);
else
return a*power(a, b/2)*power(a, b/2);
}
/* Program to test function power */
int main()
{
int a= 3;
unsigned int b= 3;

printf("%d", power(a,b));
return 0;
}

11.Write a program in C for in array 1-100 numbers are stored,one


number is missing,how do you find it

#include <stdio.h>

void main()
{
int n, i, j, c, t, b;

printf("Enter size of array : ");


scanf("%d", &n);
int array[n - 1]; /* array size-1 */
printf("Enter elements into array : \n");
for (i = 0; i < n - 1; i++)
scanf("%d", &array[i]);
b = array[0];

48
for (i = 1; i < n - 1; i++)
b = b ^ array[i];
for (i = 2, c = 1; i <= n; i++)
c = c ^ i;
c = c ^ b;
printf("Missing element is : %d \n", c);
}

12.Write a C program to insert an element at the end and at the given


location in an array

Inserting element at the End:


#include <stdio.h>
void main()
{
int position, i, n, value,ch, arr[100];
printf("C Program to insert element at end of Array\n");
printf("First enter number of elements you want in Array\n");
scanf("%d", &n);
arr[n];
for(i = 0; i < n; i++)
{
printf("Please give value for index %d : ",i);
scanf("%d",&arr[i]);
}
printf("Let's Insert Element at end \n ");
printf("Please give a number to insert at end \n");
scanf("%d", &value);
arr[n] = value;
printf("Element %d is inserted at %d index \n",value,n);
printf("New Array is \n ");

for(i = 0; i < n+1; i++)


{

49
printf("%d \t",arr[i]);
}
}

And the given location:

#include <stdio.h>
void main()
{
int loc, i, n, value,ch;
printf("C Program to insert element at end of Array\n");
printf("First enter number of elements you want in Array\n");
scanf("%d", &n);
int arr[n];
for(i = 0; i < n; i++)
{
printf("Please give value for index %d : ",i);
scanf("%d",&arr[i]);
}
printf("Please give a number to insert \n");
scanf("%d", &value);
printf("Please enter the location to insert an new element\n");
scanf("%d", &loc);
for (i = n - 1; i >= loc - 1; i--){
arr[i+1] = arr[i];
}
arr[loc-1] = value;
printf("After Insertion new Array is \n");
for (i = 0; i <= n; i++)
printf("%d\n", arr[i]);
}

13.Write a C program to find the sum of digit of numbers using recursion

#include <stdio.h>

50
int sum (int a);

int main()
{
int num, result;

printf("Enter the number: ");


scanf("%d", &num);
result = sum(num);
printf("Sum of digits in %d is %d\n", num, result);
return 0;
}

int sum (int num)


{
if (num != 0)
{
return (num % 10 + sum (num / 10));
}
else
{
return 0;
}
}

14.Write a C Program to calculate factorial using iterative method

#include<stdio.h>
int main()
{
int i,num,factorial=1;
printf("Enter a whole number to find Factorial = ");
scanf("%d",&num);
for(i=1;i<=num;i++){

51
factorial=factorial*i;
}
printf("Factorial of %d is: %d",num,factorial);
return 0;
}

15.C program to perform basic matrix operations(addition, subtraction


and multiplication) in 2 D array

#include<stdio.h>

int main()
{
int i, j, rows, columns, a[10][10], b[10][10];
int Addition[10][10], Subtraction[10][10], Multiplication[10][10];

printf("\nPlease Enter Number of rows and columns\n");


scanf("%d %d", &i, &j);

printf("\nPlease Enter the First Array Elements\n");


for(rows = 0; rows < i; rows++)
{
for(columns = 0;columns < j;columns++)
{
scanf("%d", &a[rows][columns]);
}
}

printf("\nPlease Enter the Second Array Elements\n");


for(rows = 0; rows < i; rows++)
{
for(columns = 0;columns < j;columns++)
{
scanf("%d", &b[rows][columns]);
}

52
}

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


{
for(columns = 0;columns < j;columns++)
{
Addition[rows][columns] = a[rows][columns] + b[rows][columns];
Subtraction[rows][columns] = a[rows][columns] - b[rows][columns];
Multiplication[rows][columns] = a[rows][columns] * b[rows][columns];

}
}

printf("\nAdd\t Sub\t Multi");


for(rows = 0; rows < i; rows++)
{
for(columns = 0; columns < j; columns++)
{
printf("\n%d \t ", Addition[rows][columns]);
printf("%d \t ", Subtraction[rows][columns]);
printf("%d \t ", Multiplication[rows][columns]);

}
}
return 0;
}

16.Write a program to swap two numbers without using the third variable.
Ans: main()
{ #include<stdio.h>
int main()
{
int a=10, b=20;
printf("Before swapping a=%d b=%d",a,b);

53
a=a+b;
b=a-b;
a=a-b;
printf("\nAfter swapping a=%d b=%d",a,b);
}

17.Print a semicolon using C program without using a semicolon anywhere


in the C code
Ans:
#include<stdio.h>
void main()
{
if(printf("%c",59)){}
}

18.Write a program to generate random numbers in C programming


language

#include <stdio.h>
#include <stdlib.h>
int main() {
int c, n;

printf("Ten random numbers in [1,100]\n");

for (c = 1; c <= 10; c++) {


n = rand() % 100 + 1;
printf("%d\n", n);
}

return 0;
}

54
19.Write a program to check Armstrong number in C?

#include <math.h>
#include <stdio.h>

int main() {
int num, originalNum, remainder, n = 0;
float result = 0.0;

printf("Enter an integer: ");


scanf("%d", &num);

originalNum = num;

// store the number of digits of num in n


for (originalNum = num; originalNum != 0; ++n) {
originalNum /= 10;
}

for (originalNum = num; originalNum != 0; originalNum /= 10) {


remainder = originalNum % 10;

// store the sum of the power of individual digits in result


result += pow(remainder, n);
}

// if num is equal to result, the number is an Armstrong number


if ((int)result == num)
printf("%d is an Armstrong number.", num);
else
printf("%d is not an Armstrong number.", num);
return 0;
}

55
20.Write a program to print "hello world" without using a semicolon?
#include<stdio.h>
int main()
{
if(printf("hello world")){}
return 0;
}

21.Write a C Program to convert Decimal number to Octal number

#include <stdio.h>

int main()
{
long decimalnum, remainder, quotient;
int octalNumber[100], i = 1, j;

printf("Enter the decimal number: ");


scanf("%ld", &decimalnum);
quotient = decimalnum;
while (quotient != 0)
{
octalNumber[i++] = quotient % 8;
quotient = quotient / 8;
}
printf("Equivalent octal value of decimal no %d: ", decimalnum);
for (j = i - 1; j > 0; j--)
printf("%d", octalNumber[j]);
return 0;
}

56
22. Write a C program to check given character is vowel or consonant

#include <stdio.h>
int main() {
char c;
int lowercase_vowel, uppercase_vowel;
printf("Enter an alphabet: ");
scanf("%c", &c);

// evaluates to 1 if variable c is a lowercase vowel


lowercase_vowel = (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u');

// evaluates to 1 if variable c is a uppercase vowel


uppercase_vowel = (c == 'A' || c == 'E' || c == 'I' || c == 'O' || c == 'U');

// evaluates to 1 (true) if c is a vowel


if (lowercase_vowel || uppercase_vowel)
printf("%c is a vowel.", c);
else
printf("%c is a consonant.", c);
return 0;
}

23. C Program to sort characters of string

#include <stdio.h>
#include <string.h>
int main ()
{
char str[100];
char temp;
int i, j,len;
printf("C Program to sort character in string\n");
printf("Please enter the string : ");

57
scanf("%[^\n]",str);
len = strlen(str);
for (i = 0; i < len-1; i++) {
for (j = i+1; j < len; j++) {
if (str[i] > str[j]) {
temp = str[i];
str[i] = str[j];
str[j] = temp;
}
}
}
printf("After sorting the character in ascending : %s", str);
return 0;
}

24.C program to reverse a linked list

#include <stdio.h>
#include <stdlib.h>

/* Link list node */


struct Node
{
int data;
struct Node* next;
};

/* Function to reverse the linked list */


static void reverse(struct Node** head_ref)
{
struct Node* prev = NULL;
struct Node* current = *head_ref;
struct Node* next = NULL;
while (current != NULL)

58
{
// Store next
next = current->next;

// Reverse current node's pointer


current->next = prev;

// Move pointers one position ahead.


prev = current;
current = next;
}
*head_ref = prev;
}

/* Function to push a node */


void push(struct Node** head_ref, int new_data)
{
struct Node* new_node
= (struct Node*)malloc(sizeof(struct Node));
new_node->data = new_data;
new_node->next = (*head_ref);
(*head_ref) = new_node;
}

/* Function to print linked list */


void printList(struct Node* head)
{
struct Node* temp = head;
while (temp != NULL)
{
printf("%d ", temp->data);
temp = temp->next;
}
}

/* Driver code*/

59
int main()
{
/* Start with the empty list */
struct Node* head = NULL;

push(&head, 20);
push(&head, 4);
push(&head, 15);
push(&head, 85);

printf("Given linked list\n");


printList(head);
reverse(&head);
printf("\nReversed Linked list \n");
printList(head);
getchar();
}

25.C program to print duplicate numbers with frequency in an array

#include <stdio.h>

int main()
{
//Initialize array
int arr[] = {1, 2, 3, 4, 2, 7, 8, 8, 3};

//Calculate length of array arr


int length = sizeof(arr)/sizeof(arr[0]);

printf("Duplicate elements in given array: \n");


//Searches for duplicate element
for(int i = 0; i < length; i++) {
for(int j = i + 1; j < length; j++) {
if(arr[i] == arr[j])

60
printf("%d\n", arr[j]);
}
}
return 0;
}

26.C Program to calculate factorial using recursion method.

#include<stdio.h>

long factorial(int n)
{
if (n == 0)
return 1;
else
return(n * factorial(n-1));
}

void main()
{
int number;
long fact;
printf("Enter a number: ");
scanf("%d", &number);

fact = factorial(number);
printf("Factorial of %d is %ld\n", number, fact);
return 0;
}

61

You might also like