Assignment for IMI (1)
Assignment for IMI (1)
Type qualifiers are basically the keywords that are used to modify the properties of
the existing variables.
● const
● volatile
● restrict
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.
2
4. Explain the purpose of getchar and putchar
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
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.
Bottom 4 Transpo Break the data stream into smaller segments and
Layers rt provide reliable and unreliable data delivery
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.
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.
-------------
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
-------------
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
8
-------------
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
-------------
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.
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
9
a = 0000 1110 -> After one bit left shift (14)
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.
State Diagram:
10
State Table:
Locked coin Unlocke Unlocks the turnstile so that the customer can
d push through.
The finite state machines are classified into two types such as Mealy state machine
and Moore 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.
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
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
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.
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.
15
obtained by shifting the binary segment value four times to the
left, and then adding the offset value.
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
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).
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
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
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
20
37.What is the general form of function in C?
int main()
{
char ch;
ch = 'g';
printf("%c in uppercase is represented as %c",ch, toupper(ch));
21
return 0;
}
No. "int" data type is capable of storing values from -32768 to 32767.
To store 32768, you can use "long int" instead.
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.
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.
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."
24
50.What is the difference between the expression “++a” and “a++”?
25
53.Define the term Testing.
26
54.Define Test Cases.
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.
28
61.What is SDLC?
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.
64.What is TBrun?
32
65.Explain Dynamic coverage analysis
33
Questions on AVR and bare metal programming
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).
● 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
ADC Register.
36
REFS1 REFS0 Vref to
ADC
0 1 AVCC pin
i.e. Vcc 5 V
1 0 Reserved
1 1 Internal 2
37
77.What is Framing
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.
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;
}
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;
// If current bit is 1
if (N & 1)
{
count1s++;
}
43
// If current bit is 0
else
{
count0s++;
}
N = N >> 1;
}
int main()
{
// Given Number
int N = 8;
// Function Call
count1sand0s(N);
return 0;
}
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;
}
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;
}
#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>
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;
}
#include <stdio.h>
void main()
{
int n, i, j, c, t, b;
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);
}
49
printf("%d \t",arr[i]);
}
}
#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]);
}
#include <stdio.h>
50
int sum (int a);
int main()
{
int num, result;
#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;
}
#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];
52
}
}
}
}
}
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);
}
#include <stdio.h>
#include <stdlib.h>
int main() {
int c, 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;
originalNum = num;
55
20.Write a program to print "hello world" without using a semicolon?
#include<stdio.h>
int main()
{
if(printf("hello world")){}
return 0;
}
#include <stdio.h>
int main()
{
long decimalnum, remainder, quotient;
int octalNumber[100], i = 1, j;
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);
#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;
}
#include <stdio.h>
#include <stdlib.h>
58
{
// Store next
next = current->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);
#include <stdio.h>
int main()
{
//Initialize array
int arr[] = {1, 2, 3, 4, 2, 7, 8, 8, 3};
60
printf("%d\n", arr[j]);
}
}
return 0;
}
#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