Modern Education

FAQ Of Embedded Systems Course

FAQ Of Embedded Systems Course

Hello friends,
When students to PTInstitute join embedded system training in Bangalore then they are having many questions in their mind. But I had seen some pattern in the question students are asking. Some students are just asking a question related to placement while some are asking for a fee, some are asking for PG or some are asking for food. Many times I feel students are not able to ask complete questions related to Professional Training Institute. So here I had compiled all common questions students generally asking, arrange them in the frequency of they inquired, and answered. Still, we keep collecting questions and keep updating this document so that it will be always updated for a document for the student.

1. Does the placement provide?

At Professional Training Institute, we are having a dedicated team, who is working in the placement of our students. We are contentiously in touch with the companies and as soon as companies are having opening they share with us. So From our side, we are sure we will provide you companies interview. The clearing interview is still in your hand. Normally students can clear interviews after attending 6-7 interviews.

2. How much time do I need to get a job?

Time entirely depends upon the student. In past we have seen a student who get placed within 3 rd month they joined our institute, on other hand, we observe some student are taking more than 8 months. From Professional Training Institute side we keep providing you interview opportunity, you need to clear as soon as possible.

3. How many interview calls provided?

Until you are getting placed. Of-course companies should have an opening and your education criteria should match with company requirements.

4. What if I did not get even after completing the training?

Normally students can crack the interview with 6-7 interview, but still due to any reason if any student is not able to clear the interview then we are having an internship program for our student, students are having the opportunity to join as an intern in our organization and work with us ongoing industrial projects. For the internship period student will get the experience certificate as an intern in our organization.

5. How much salary/package I will get?

Salary varies from company to company some companies are offering 4.5 Lpa or some companies are offering 2.2 LPA. In an average embedded fresher gets in between 12,000 to 25,000 initially. Salary is a complete matter between you and the company. You need to directly discuss with the company and finalize it?

6. What if after selection I don’t want to join the company?

We are having one placement policy, it means once you get placement from our institute then we will stop working for your placement.

7. I have fewer % marks does it impact on placement?

Some companies are not asking for % marks but some companies are asking for 70%+ or 80%+. so during placement, it will impact in terms of the number of companies you will attend. But we are very much sure you defiantly get a placement opportunity. You should learn more practical and hands-on So that should be ready to crack the interview as soon as you get an interview opportunity. After getting 2-3 years of experience % marks don’t matter.

8. What is the maximum package I will get?

The maximum package depends upon companies, as per our understanding of the market is embedded fresher is getting 12,000 to 25,000 per month in beginning. Although the package is a complete matter of you can company, you can show your caliber and ask for more money.

9. Do the companies are MNCs or small?

Our students are working in all types of companies including Big MNCs to small start-ups. When some companies are giving us requirements then we are discriminating between big or small instead we are focusing on than nature of the job. We entertain embedded development/ embedded testing/ embedded hardware companies only. You can visit our placement section and see the list of companies’ shared requirements with us.

10. Do we have to go for an interview or companies are visiting the institute?

It depends upon the individual company. Some companies are visiting us while some companies are asking us to send a student to their location for an interview.

11. In the Interview what companies are asking?

Companies are looking for development skills, they check students for the problem-solving capability. Companies also want to know whether students are capable to solve new problems with analytical understanding or not. The company main focus on C language, 90% embedded interview will be based on C language. Embedded is a different kind of thinking, so you should have an understanding of the embedded system.

12. Does this is a guaranteed placement?

From our side, we can ensure you will get a placement opportunity, but interview clearing will still in your hands.

13. What if I don’t get a job even after training?

If you attending all classes and doing all assignment on time, then there is a huge chance you will be getting a place with our placement cell, but if still you not able to clear the interview or due to market condition if less placement opportunity is available then you can do an internship with our organization. You will get the experience certificate for the said duration.

14. Does the institute also help in soft skills training?

Yes, we focus on every individual student, so whatever is needed to get a clear interview we are assisting.

15. What we have to write on a resume? Does the institute help in making a resume also?

Once the placement is started for you then we will review your resume and make them properly. A resume is the first impression on the employer.

16. After how many months of the training placement process will starts?

As soon as C language training is complete, then we start the placement process for the student. It usually takes 3 months to start the placement process.

17. How many rounds in the interview?

This depends upon the individual company some are taking one round while some companies are taking 5-7 rounds.

18. Does the company ask aptitude also in the first round?

Yes, some companies are asking aptitude in the first round. But still, they have a focus on Technical knowledge only.

19. What all companies have visited the institute? Where I can get a list of companies?

As soon as companies are having opening they share information with us. You can see the list of companies share the requirement with us in our placement section.

20. What is the batch size?

We are having one to one training method, in this method every individual student is learning independently. We start classes in batch but after a few classes, some students are finishing assignments very fast while some are taking the time. We are not stopping fast-moving students as well as we are not asking the slow student to leave the contains and join the next class. Every individual student needs to finish all assignments.

So when it comes to batch size may be in some class 100 students are setting while in some class 2 students are setting it completely depends upon the individual student. So we are having a variable batch size.

21. What are the training methods? What is one to one training method, how it works?

Our training method is one to one, every student needs to complete its assignments. We start training in batch but students do assignments at their speed. Some can move fast while some not. When it comes to embedded development student need to write complete firmware by own hand and make an embedded project working, that gives complete hands-on and clear understanding of the embedded system. We encourage our students to ask the question as much as possible, the asking question gives more and more outstanding of subjects. Our focus is more on the student as start thinking in terms of technical terms.

22. Do we have practical also?

Yes, Our full training is based on practical and hands-on.

23. How many hours per day class?

Students stay in the institute approximately 3-4 hours per day. But students will always have assignments with then, they keep doing an assignment in their home/PG also and they can in case of any issue or problem they are connected with us using call/WhatsApp, etc.

24. How many trainers are in the institute?

Currently, we are having 4 trainers working with us.

25. What is the experience of the trainer?

All our trainers are having a very high industrial experience they are keep working keep sharing their real-time experience with our students. Our teaching method is completely industrial oriented. The trainer is having more than 18 + years of embedded development experience in industries. In though our his career he is working in embedded design and development.

26. Why industries experts are visiting to institute? What information do they share with students?

Many industry experts are keeping visiting our institute and meeting with the student, they keep sharing knowledge and understanding about the system, industries, and the expectation of companies. Students can learn many new concepts from industries exports. Students can ask direct questions and make understand their future path and growth.

27. Do I have to buy software or hardware for the lab?

No, we provide all hardware and software to perform practical in our institute, if you want to experiment at your home then you need to buy devices personally.

28. Does the institute provide training material?

Yes, we provide all the training material required.

29. How many projects we have to make?

During the training, students need to make 3-4 projects. Some are minor projects while some are major projects.

30. Does the project are industry level?

Yes, we are having a list of industry-level projects, student can choose their project from the list and make as a final project.

31. Which microcontroller is using for training?

We are providing embedded system training such ways that students will able to use any microcontroller. We make a clear concept of an embedded system. For our experiment, we use an 8051 microcontroller, and fro the project we use STM32Fxxxx controllers they are ARM Cortex controllers.

32. Does in practical raspberry pi is also used?

Yes, the student can choose and make a project using a raspberry pi or ESP32.

33. How many leaves do we take during training?

No leaves are allowed during training until otherwise discussed and approved in advance.

34. Does PGs are available near to the institute?

Yes, we are surrounded by many Girls / Boys PG around our institute.

35. How much I have to spend per month for PG?

PG is charging 4,500 per month including 3 times food. It can range from 40,00 to 10,000 based on individual choice.

36. Can we pay fees in installments? How many installments are allowed?

Yes, we allowed our students to pay the fee in 3 installments.

37. Why a professional training institute is the best institute in Bangalore?

There are many reasons the main reason is our teaching method, we are having one to one training methods. This gives every individual learning. We ensure that every student is learning and getting a job as soon as possible. Another reason for the best training institute in Bangalore is our training is having more than 18 years of experience in embedded development, and students are directly learning for him. For placement, we keep helping our students until they are getting jobs.
In our institute, we are making a family-like relationship, that extends our attachment with the student forever. We are sure we are the best to learn and gain knowledge in an embedded system. So we welcome you to come and explore the possibilities ahead.

What Is Deep Learning

What is Deep Learning

What is deep learning, nowadays many students want to know about it? Deep learning is another branch of the embedded system, in embedded system data collected by the sensor is in the core of the algorithm. Before starting deep learning is will be advantages to embedded system training in Bangalore, it will help you to get understanding and collecting sensor data.

Deep learning is part of a big family of machine learning, here we mainly focus on deep learning. With deep learning, the algorithm computer is capable of learning like a brain. In simple words, when we are child our brain learning by touching, smelling, tasting, and feeling. Similar ways computers also capable to learn slowly one by one, step by step using a deep algorithm like a neural network. Using a neural network computer is capable to extract complicate concepts and relationships of data.

In deep learning computer use data like picture, sound, video, text, and established complex the relationship among these data, this learning computer remember and uses in the next algorithm. In deep learning, we are having many more data sets, which is used for learning to teach computers. Using deep algorithm computers take the complex decision and use these decisions for the next algorithm. In deep learning, we need to focus on speed, scalability, and flexibility.

Speed:

We have to design a deep learning algorithm so that computers are capable of learning quickly. In order to learn faster computers need many more CPUs and GPUs to solve complex matrix. Using high-speed CPUs and GPUs user can speed up computer deep learning.

Scalability:

Consider the case when we have written the algorithm to lean COVID-19 spread in the world, soon after the deep learning algorithm computer can able to tell how COVID-19 going to spread in the future, we continuously need to feed new data so that we get correct prediction in advance.

Flexibility:

During algorithm many, we may need to use much software that required very high computation power. So we need to choose a deep learning algorithm that is best suited for our algorithm.

Now we will see what is the use of deep learning and where we are using deep learning. Nowadays across the world, many companies are working in deep learning.

Computer Vision:

In the application of computer vision, face recognition is most widely used. Although there are millions of applications of computer vision, like production control, quality inspection, autonomous driving cars, etc. In computer vision, We take input from a camera, sound, heat and proximity data, using all input computer vision is created which is capable to detect the face of human, or quality inspection at a faster rate, or drive a car automatically.

Speech Recognition:

Speech recognition is another important application of deep learning. On every smartphone. We are having voice command using google voice, Amazon Alexa, Microsoft Cortana, Apple Siri are the major name among many more which can recognize input voice, take action on them and analyze for future use.

Dealing With Malware:

Deep learning can help a lot in malware analysis and protect computer users. In new world malware attach are a very severe effect. Nowadays malware can theft user data and it use for many scams.

Network Traffic Analysis:

Deep learning is very useful for our country, much tarriest organization are using the internet for communication among their team, using deep learning communication can track and used for security purposes.

User Behavior Analysis:

When a customer is visiting the shopping mall, he is keep seeing many products and then chose few, while another customer is just directly going and buying a product. These varying behavior can we understand properly using IoT and embedded systems. With deep learning we will able to predict the product customer is going to buy, these deep learning can help to suggest the product user is interested in buying.

Here in Professional Training Institute, we are mainly focusing on embedded system training, Linux device driver, Embedded Linux, and IOT training. Our teaching method is completely practical and hands-on. We are a best-embedded system training institute in Bangalore.

All about Process in Linux/Unix – Developer Perspective

PROCESS:

In Linux every thing we sees executing or taking some action will be by the process. Processes carry out tasks within the operating system. For definition ” Any program in execution is called process”.  A program is a set of machine code instructions and data stored in an executable area of memory.

Processes are separate tasks each with their own rights and responsibilities. Each individual process runs in its own address space and not interacting with another process except through secure, kernel managed mechanisms.

LINUX PROCESS:-

An instance of a program is called a Process. In simple terms, any command that you give to terminal on your Linux machine starts a new process. Having multiple processes for the same program is possible. A process itself not a process, until it comes info execution.

In a Linux system no process is independent of any other process. Every process in the system, except the initial process has a parent process. New processes are not created, they are copied, or cloned from previous processes.

Types of Process:-

  • Foreground Process: A foreground process is any command or task you run directly and wait for it complete. They run on the screen and need input from the user.

A foreground Process begins by typing a command at prompt. For example, list of files in current directory

>ls
  • Background Processes: In Linux, a background process is nothing but process running independently. They run in the background and usually do not need user input.

For example

  • Antivirus in your computer, normally it is running in background.

 

Basic command for Linux process:-

ps:

The ps command is used to provide information about the currently running process, including their process identification number(PID).

The basic syntax of ps is

>ps

When ps is used without any option, which display default  information of process currently running on the system .

The four items are labeled PID,TTY,TIME,CMD

PID-  Process identification number.

TTY- TTY is the name of console or terminal shows currently console.

TIME- Time is the amount of CPU, time in minutes and seconds that the process has been running.

CMD- Cmd is the name of the command that launched the process.

 

 

 

 

ps –e:-

ps –e command is used for list of all process running on the system in a single shot

>ps –e
  • –e show all process not just those belonging to user.

 

 

 

 

 

 

 

 

 

 

 

 

pstree:-

pstree is a command that shows the running processes as a tree fromat. It  is  used as a alternative to the ps command.

The basic syntax of the pstree is

>pstree

pstree command is similar to the ps command, but instead of listing the running processes ,it shows in a tree format.

 

 

 

 

 

 

 

 

 

 

bg:-

Linux treats everything as file, even the processes as files under /proc directories. The processes are basically program in execution, they also called jobs

The bg command is the processes that have been stopped by some interrupt signal can be continued background with bg command

Syntax for bg command

  • ./output &

 

 

 

fg:-

The  fg command  is like bg command Except that instead of sending a command in the background it runs them in foreground and occupies the current terminal and wait for process to exit.

top:-

In Linux, top is a command used to display processor activity of your linux , this command shows the  information of the system and the list of processes  which are currently running in the Linux

 

 

 

 

 

 

 

 

 

 

 

 

  • PID:Shows task’s unique process id.
  • PR: Stands for priority of the task.
  • SHR:Represents the amount of shared memory used by a task.
  • VIRT:Total virtual memory used by the task.
  • USER:User name of owner of task.
  • %CPU: Represents the CPU usage.
  • TIME+:CPU Time, the same as ‘TIME’, but reflecting more granularity through hundredths of a second.
  • SHR:Represents the Shared Memory size (kb) used by a task.
  • NI:Represents a Nice Value of task. A Negative nice value implies higher priority, and positive Nice value means lower priority.
  • %MEM: Shows the Memory usage of task.

 

Kill

kill command in Linux (located in /bin/kill), is a built-in command which is used to terminate processes manually. kill command sends a signal to a process which terminates the process.

 

EXAMPLES

> kill -9 -1        Kill all processes you can kill.

> kill -l 11         Translate number 11 into a signal name.

> kill -L             List the available signal choices in a nice table.

> kill 3453         Send the default signal, SIGTERM, to all those processes.

 

Now we will learn the Process with the developer prospective, here user can write C program using any editor wish and compile code using GCC.

Process  Identification:-

In Linux, User can be running various programs in the system, each running program must be unique identified by the kernel and program id identified by its own process is called “PID”, therefore process can be further categorized into

  • Parent process.
  • Child process.

Parent process-Parent process is processes that create other processes during run-time.

In command prompt, Command to get the parent process identity.

Header file need to include for getpid():

  • Sys/types.h
  • unistd.h
getppid()

Child process-Child process are created by the parent process by cone of it ,it will be behaves same as parent.

In command prompt, Command to get the child process identity.

Header file need to include for getppid():

  • Sys/types.h
  • unistd.h
getpid()

 

Now our first steps is to create process, fork is the system call which is used to create process. read on and follow –

Frok():-

Fork is a way to create new processes, fork() operation create a separate processes as a copy of itself then, the copy called the “child process”.

The child process has an exact copy of  the parent process. After the fork, both processes not only run the same program

The child has its own unique process ID and this PID not match the ID of any existing process

The child parent process ID is the same as the parent’s process ID.

Return value:

On success, the PID of the child is returned in the parent, and “0” is returned in the child. On failure, “-1” is returned in the parent, no child process is created and errno is set appropriately.

 

Header file need to include for fork:

 

unistd.h

 

 

 

 

 

 

 

 

 

 

 

Sleep():-

In Linux, Sleep() I s causes the calling thread to sleep either until of real-time specified in seconds have to elapsed .

Steps for sleep():-

Step 1– write a source code for sleep(), as shown in below image.

Step 2– Search for PID in all current running processes, by giving command ps.

Step 3-Enter in /proc and search that Pid by using ls command.

Step 4– Enter the Pid proc type cat status for the process states. Now you should be in /proc/pidof_yourprocess. Steps shown below.

$cd /proc <┘

$ls <┘

$cd  /proc/pid <┘

$cat status <┘

Now see the status of process, it will show process is sleeping.

 

 

 

 

 

 

 

 

 

 

 

 

 

Now check the status of process, that is sleeping.

 

 

 

 

 

 

 

 

 

wait system call

wait()  blocks the calling process until one of its child processes exits or a signal is received. After child process terminates, parent continues its execution after wait system call instruction.

Header files for wait:

  • sys/wait.h

 

 

 

 

 

 

 

 

 

 

Exec System calls family:-

 

  • Exec family of function or system call replace current process with new process.
  • There are various function used in the Exec  like
    • Execl
    • Exclp
    • Execle
    • Execve
    • Execvp
    • Execvpe

Header file need to include is

unistd.h

Example for execlp:-

 

 

 

 

 

 

 

 

Orphan process:-

Orphan processes are those processes that are still running even though their parent process has terminated or finished. A process can be orphaned intentionally or unintentionally.

An intentionally orphaned process runs in the background without any manual support. This is usually done to start an indefinitely running service or to complete a long-running job without user attention.

An unintentionally orphaned process is created when its parent process crashes or terminates. Unintentional orphan processes can be avoided using the process group mechanism.

Zombie process

Zombie processes usually occur for child processes, as the parent process still needs to read its child’s exit or crashes . Once this is done using the wait system call, the zombie process is eliminated from the process . This is known as the zombie process.

Professional Training Institute is the top embedded training institute in Bangalore, where student can learn the practical embedded system, we believe in hands on knowledge of subject such that student are not only getting the practical knowledge but also getting experience in embedded system development. All our students are able to get placed in top companies with the knowledge they gain in our institute. come and explore the possibilities, of amazing knowledge you can gain.

INTERFACING LCD 16*2 WITH 8051

INTERFACING LCD 16*2 WITH 8051

SUMMERY:

Connecting LCD 16*2 display to the 8051 microcontroller in 8 bitration method and also passing two commands.

COMPONENTS RECQURIED:

o 8051 Microcontroller
o 16*2 LCD Display
o Switch
o Binary Wires
o Power Supply

PIN DIAGRAM:

 

 

 

 

 

 

 

 

 

SOURCE CODE:


#include 
# define lcd P0 
sbit rs=P1^0; 
sbit e=P1^1; 
sbit b=P1^2; 

void dealy50ms(int a); 
void intial(char b); 
void delay1s(unsigned char c); 
void write1(); 
void write2(); 
void write3(); 
void write4(); 
void button() 
{
	int k=1; 
	while(k==1)
	{ 
		if(b==0)
		{ 
			intial(0x01); 
			k=0; 
		}
	}
} 

void display(char *d); 

int main() 
{ 
	b=1; 
	while(1)
	{ 
		intial(0x38); 
		intial(0x0c); 
		intial(0x01); 
		intial(0x80); 
		write1(); 
		intial(0xc0); 
		write2(); 
		button(); 
		intial(0x80); 
		write3(); 
		intial(0xc0); 
		write4(); 
	} 
} 

void display(char *d)
{ 
	for(*d;d!=NULL;d++)
	{ 
		lcd=*d;
		rs=1; 
		e=1; 
		delay1s(1); 
		e=0;
	}
} 
void write1()
{ 
	display("Done LCD16*2 ");
}

void write2() 
{
	display(" SUCESS ");
}

void write3() 
{
	display("Thank");
}

void write4()
{
	display("YOU");
}

void intial(char b) 
{
	lcd=b;
	rs=0;
	e=1;
	dealy50ms(2);
	e=0; 
} 

void dealy50ms(int a) 
{
	inti=0; 
	for(i; i < a ; i++) 
	{
		TMOD=0x01;
		TH0=0xff; 
		TL0=0xfc;
		TR0=1; 
		while(!TF0);
		TF0=0;
		TR0=0; 
	}
}

void delay1s(unsigned char c)
{
	int i,j;
	for(i=0;i < c;i++)
	{
		for(j=0;j<20;j++) 
		{
			TMOD=0x01; 
			TH0=0xff; 
			TL0=0xfc; 
			TR0=1;
			while(!TF0);
			TF0=0;
			TR0=0;
		}
	}
}

EXPLIANATION:

Now we will go through code and understand how LCD is working. Any C programalways start with main function. In our code main function contains.


int main()
{ 
	b=1; 
	while(1)
	{ 
		intial(0x38); 
		intial(0x0c); 
		intial(0x01); 
		intial(0x80); 
		write1(); 
		intial(0xc0); 
		write2(); 
		button(); 
		intial(0x80); 
		write3(); 
		intial(0xc0); 
		write4(); 
		} 
	}
}
Main function is started
intial(0x38); command 0x38
intial(0x0c);Passing 0x0C value for Display ON, Cursor OFF
intial(0x01);Passing 0x01 value for Clear the screen
intial(0x80);Passing 0x80 value for Force curser to the 1st line in first position
Write1();Calling write1 function to pass the “Done LCD 16*2 ” string to display function

Next how to send the commands through intial function to LCD


void intial(char b) 
{ 
	lcd=b; 
	rs=0; 
	e=1; 
	dealy50ms(2); 
	e=0; 
}
In Intial function, Passing the command from Microcontroller P0 to LCD through parallel communication from Microcontroller(P0.0-P0.7) to LCD(D0-D7). “rs” register pin used to set 1 or 0 is used to sending commands. “e” enable pin used to given value to LCD as making high to low.
Professional Training Institute is highly focus on practical embedded system training in Bangalore, Above post is writtern by our student Joy and Prathavi. We wish bright carrer ahead to both of them.

Next is interfacing button to the LCD to send different string data

 


void button()
{ 
	int k=1; 
	while(k==1)
	{ 
		if(b==0)
		{
			intial(0x01); 
			k=0; 
		} 
	}
}
In button function, Run the while part to check every time the value of k. b is connected to the switch when it pressed it becomes zero, It is initially high condition(1). Passing the value 0x01 to clear the screen. Once button is clicked the value of “k” changed to 0 to exit the while loop.

Next to pass the string value to the LCD through display function

 


void display(char *d)
{ 
	for(*d;*d!=NULL;d++) 
	{ 
		lcd=*d; 
		rs=1; 
		e=1; 
		delay1s(1); 
		e=0; 
	} 
}
Display function getting the string’s first address. rs is the register pin used to intimate the LCD as it is a data not a command. e is a enable pin used to given value to LCD as making high to low.

Next delay function for 50ms

 


void dealy50ms(int a)
{
	inti=0; 
	for(i;i<a;i++)
		{
			TMOD=0x01;
			TH0=0xff; 
			TL0=0xfc; 
			TR0=1; 
			while(!TF0); 
			TF0=0; 
			TR0=0; 
			} 
		}
}
Here is the delay function for 50ms you maximize the value through passing number to make higher, this is done trough using Timer concept

Next is the delay for 1s

 


void delay1s(unsigned char c)
{ 
	inti,j; 
	for(i=0;i<c;i++) 
	{ 
		for(j=0;j<20;j++) 
		{ 
			TMOD=0x01; 
			TH0=0xff; 
			TL0=0xfc; 
			TR0=1; 
			while(!TF0); 
			TF0=0; 
			TR0=0; 
		} 
	} 
}
Here is the same but used delay function for 1s you maximize the value through passing number to make higher, this is done through using Timer concept

From above the program it is written for 8 bitration of 16*2 LCD display for 2 commands. Here I used common initialisation command for all 16*2 LCD display which is in intial( ); and the strings are written in write1..4( ) functions and the display commands of working procedures also written in the display( ) function and also two different delays are represented as 50ms and 1s in delay50ms( ) and delay1s( ) function which is written in timer concept.
Professoinal Training Institute is focus in Practical embedded system training in Bangalore. This post is written by our student Joy and Prathavi, based on their executed experiments during training. we wish then for their bright career ahead.

Alternet Working Source Code:


#include 
#define Display_Port P0
// Selecting a display port P0 
sbit RS = P1^0; 
// Selecting Resistor Selection 
Port P1.0 
sbit EN = P1^1; 
// Port P1.1 for Enable Pin 
sbit button = P1^2; 
void delay_ms(int d);
// Function Prototype to generate mili second delay 
void lcd_data(char display_data); 
// Function Prototype to send information on LCD display 
void lcd_int(); 
// Function Prototype to initilization of Basics LCD Commands 
void lcd_command(char command); 
// Function Prototype to send commands on LCD Port 
/* .................Begining of Main Function .....................*/ 

void main() 
{ 
	inti=0; 
	int j=0; 
	int k=0; 
	int l=0; 
	int check = 1; 
	unsigned char a[9]="EMBEDDED"; 
	unsigned char b[8]="DESIGN"; 
	unsigned char c[6]="THANK"; 
	unsigned char d[4]="YOU"; 
	button =1; 
	lcd_int(); 

// LCD Initilization 
// button = 1; 

	while( a[i] != '\0' )
	{
		lcd_data(a[i]);
		i++;
		delay_ms(50);
	} 
	lcd_command(0xC0); // Command to Move Cursor to next line 
	while(b[j] != '\0') 
	{
	lcd_data(b[j]);
	j++; 
	delay_ms(50);
	}
	lcd_command(0x0C); // Command to set Display ON Curser OFF 
	//delay_ms(2000); // Delay for 2sec 
	while(check==1)
	{ 
		if(button == 0)
		{
			lcd_command(0x01); // Command To clear screen 
			check = 0; 
		} 
	} 
	while(c[k]!='

#include 
#define Display_Port P0
// Selecting a display port P0 
sbit RS = P1^0; 
// Selecting Resistor Selection 
Port P1.0 
sbit EN = P1^1; 
// Port P1.1 for Enable Pin 
sbit button = P1^2; 
void delay_ms(int d);
// Function Prototype to generate mili second delay 
void lcd_data(char display_data); 
// Function Prototype to send information on LCD display 
void lcd_int(); 
// Function Prototype to initilization of Basics LCD Commands 
void lcd_command(char command); 
// Function Prototype to send commands on LCD Port 
/* .................Begining of Main Function .....................*/ 
void main() 
{ 
inti=0; 
int j=0; 
int k=0; 
int l=0; 
int check = 1; 
unsigned char a[9]="EMBEDDED"; 
unsigned char b[8]="DESIGN"; 
unsigned char c[6]="THANK"; 
unsigned char d[4]="YOU"; 
button =1; 
lcd_int(); 
// LCD Initilization 
// button = 1; 
while( a[i] != '\0' )
{
lcd_data(a[i]);
i++;
delay_ms(50);
} 
lcd_command(0xC0); // Command to Move Cursor to next line 
while(b[j] != '\0') 
{
lcd_data(b[j]);
j++; 
delay_ms(50);
}
lcd_command(0x0C); // Command to set Display ON Curser OFF 
//delay_ms(2000); // Delay for 2sec 
while(check==1)
{ 
if(button == 0)
{
lcd_command(0x01); // Command To clear screen 
check = 0; 
} 
} 
while(c[k]!='\0') 
{ 
lcd_data(c[k]);
k++;
delay_ms(50); 
}
delay_ms(20); 
lcd_command(0xC0); // Move cursor to nest line 
while(d[l]!='\0') 
{ 
lcd_data(d[l]); 
l++; 
delay_ms(50); 
} 
while(1);
} 
/*................. END of Main Function .........................*/ 
/*................. Delay Sub Routile............................*/ 
void delay_ms(int d) 
{
inti,j; 
for(i=0; i<d; i++)
for(j=0; j<1257; j++); 
}
/*.....Sub Routine to send information over LCD...............*/ 
void lcd_data(char display_data)
{
Display_Port = display_data; 
RS = 1; 
EN = 1; 
delay_ms(1); 
EN = 0; 
} 
/*....... Sub Routine to send Commands over LCD Display.............*/ 
void lcd_command(char command) 
{ 
Display_Port = command; 
RS = 0; 
EN = 1; 
delay_ms(1); 
EN = 0; 
} 
/*........... Sub Routine to initilize the Commands............*/ 
void lcd_int()
{
lcd_command(0x38); 
delay_ms(10); 
lcd_command(0x0F); 
delay_ms(10); 
lcd_command(0x01); 
delay_ms(10); 
lcd_command(0x80);
delay_ms(10); 
}
') { lcd_data(c[k]); k++; delay_ms(50); } delay_ms(20); lcd_command(0xC0); // Move cursor to nest line while(d[l]!='

#include 
#define Display_Port P0
// Selecting a display port P0 
sbit RS = P1^0; 
// Selecting Resistor Selection 
Port P1.0 
sbit EN = P1^1; 
// Port P1.1 for Enable Pin 
sbit button = P1^2; 
void delay_ms(int d);
// Function Prototype to generate mili second delay 
void lcd_data(char display_data); 
// Function Prototype to send information on LCD display 
void lcd_int(); 
// Function Prototype to initilization of Basics LCD Commands 
void lcd_command(char command); 
// Function Prototype to send commands on LCD Port 
/* .................Begining of Main Function .....................*/ 
void main() 
{ 
inti=0; 
int j=0; 
int k=0; 
int l=0; 
int check = 1; 
unsigned char a[9]="EMBEDDED"; 
unsigned char b[8]="DESIGN"; 
unsigned char c[6]="THANK"; 
unsigned char d[4]="YOU"; 
button =1; 
lcd_int(); 
// LCD Initilization 
// button = 1; 
while( a[i] != '\0' )
{
lcd_data(a[i]);
i++;
delay_ms(50);
} 
lcd_command(0xC0); // Command to Move Cursor to next line 
while(b[j] != '\0') 
{
lcd_data(b[j]);
j++; 
delay_ms(50);
}
lcd_command(0x0C); // Command to set Display ON Curser OFF 
//delay_ms(2000); // Delay for 2sec 
while(check==1)
{ 
if(button == 0)
{
lcd_command(0x01); // Command To clear screen 
check = 0; 
} 
} 
while(c[k]!='\0') 
{ 
lcd_data(c[k]);
k++;
delay_ms(50); 
}
delay_ms(20); 
lcd_command(0xC0); // Move cursor to nest line 
while(d[l]!='\0') 
{ 
lcd_data(d[l]); 
l++; 
delay_ms(50); 
} 
while(1);
} 
/*................. END of Main Function .........................*/ 
/*................. Delay Sub Routile............................*/ 
void delay_ms(int d) 
{
inti,j; 
for(i=0; i<d; i++)
for(j=0; j<1257; j++); 
}
/*.....Sub Routine to send information over LCD...............*/ 
void lcd_data(char display_data)
{
Display_Port = display_data; 
RS = 1; 
EN = 1; 
delay_ms(1); 
EN = 0; 
} 
/*....... Sub Routine to send Commands over LCD Display.............*/ 
void lcd_command(char command) 
{ 
Display_Port = command; 
RS = 0; 
EN = 1; 
delay_ms(1); 
EN = 0; 
} 
/*........... Sub Routine to initilize the Commands............*/ 
void lcd_int()
{
lcd_command(0x38); 
delay_ms(10); 
lcd_command(0x0F); 
delay_ms(10); 
lcd_command(0x01); 
delay_ms(10); 
lcd_command(0x80);
delay_ms(10); 
}
') { lcd_data(d[l]); l++; delay_ms(50); } while(1); } /*................. END of Main Function .........................*/ /*................. Delay Sub Routile............................*/ void delay_ms(int d) { inti,j; for(i=0; i<d; i++) for(j=0; j<1257; j++); } /*.....Sub Routine to send information over LCD...............*/ void lcd_data(char display_data) { Display_Port = display_data; RS = 1; EN = 1; delay_ms(1); EN = 0; } /*....... Sub Routine to send Commands over LCD Display.............*/ void lcd_command(char command) { Display_Port = command; RS = 0; EN = 1; delay_ms(1); EN = 0; } /*........... Sub Routine to initilize the Commands............*/ void lcd_int() { lcd_command(0x38); delay_ms(10); lcd_command(0x0F); delay_ms(10); lcd_command(0x01); delay_ms(10); lcd_command(0x80); delay_ms(10); }

Interview Q and A 9

Interview Q and A 9



Ques 1. How to know the given controller is little endian or big endian ?

#include <stdio.h>
#include <stdlib.h>
int main()
{
    unsigned int x=0xaa55;
    unsigned char *p=&x;
if(*p == 0x55)
{
    printf("\n Little endian");
    printf("%x = %x\n",p, *p);
    printf("%x = %x\n",(p+1),*(p+1));
}
else
    printf("\n Big endian");
    return 0;
}


Ques 2. what is the output for the below code?
#include <stdio.h>
#include <stdlib.h>
int main()
{
    int a=5;
    {
      int a=9;
      printf("\n %d",a);
    }
    printf(" %d",a);
    return 0;
}

Ans. 9 5


Ques 3. what is the output for the below code?
#include <stdio.h>
#include <stdlib.h>
int main()
{
    int a=5;
    {
      a=9;
      printf("\n %d",a);
    }
    printf(" %d",a);
    return 0;
}

ans :  9 9



Ques 4. What is the difference between General purpose os and RTOS ?

RTOS :
  Rtos scheduling is based on priority
  Resopnse time is predictable
  kernel is preemptive or upto maximum degree
  priority inversion is a major issue
  it has less memory

Ex: Free RTOS, vxworks, RT linux, PSOS, VRTX, Lynx

General Purpose OS:
  GPOS scheduling  can be adjusted dynamically for optimized throuhput.
  Resopnse time is not predictable
  kernel is non preemptive or upto maximum degree
  priority inverson is unnoticed.
  it is having large memory.
 Ex: Microsoft windows, Redhat Linux, Apple MacOS


Ques 5. explain the meaning of below declaration?

const int PI, int const PI, const int *p,  int * const p, const int *const p;

const int PI : PI is a integer constant.
int const PI : PI is a integer constant.
const int *p:  p is a pointer to constant integer, data present in p is constant and ponter is not constant.
int * const p: pointer p is constant and data is not constant.
const int * const p: both pointer p and data are constant. 


Ques 6. what are the bitwise operators and its types?

bitwise operators are as mentioned below:

| bitwise or operator   
& bitwise and operator
~ bitwise 1's complement operator
^ bitwise xor operator
<< bitwise left shift operator
>> bitwise right shift operator.


Ques 7. which operator is suitable for checking perticular bit is set or not?
 >> and & operators.


Ques 8. what is the output for the below code?
int main()
{
    int a=3;
    int x=-15;

    a+x > 5? puts("a+x > 5 "): puts("a+x < 5");

    return 0;
}


ans: a+x < 5


Ques 9. write a program to swap two numbers without using third variable?

swap(int *p, int *q)
{
  *p=*p+*q;
  *q= *p-*q;
  *p=*p-*q;
}


Ques 10. write a program to pass array as argument to a function?

fun(int p[])
{
  int i=0;
  for(; i<3; i++)
  printf(" = %d \n", p[i]);

}

int main()
{
    int a[3] ={2,3,4};
    fun(a);
    return 0;
}


Ques 11. what is ohms law?
ohms law states that the current through the conductor is directly proportional to the voltage across
the two points of the conductor with resistance is constant.


Ques 12. what is the difference between call by value and call by reference ?
	call by value means we are passing copy of the original arguments to the formal arguments of the function.
             here the value changed in the formal arguments will not affect the original arguments 
	call by referece means we are passing the address of the arguments to the formal arguments of the function.
             here the value changed in the formal arguments will affect the original arguments.

Ques 13. what is the output for the below code if integer size is 4 bytes?

int main()
{
	int x=-1;
	printf("%x ", (x>>1));
	return 0;
}

ans : ffffffff


Ques 14. what is the equivalent pointer expression for the array element arr[i][j][k][m]?

ans:     *(*(*(*(arr+i)+j)+k)+m)


Ques 15. what is the output for the below code?

int main()
{
	int *p, **q, ***r;
	int x=9;
        p=&x;
	q=&p;
	r= &q;
	printf("%d %d %d", *p, **q, ***r);
	return 0;
}

ans: 9 9 9



Ques 16. what is the requirement of infinite loop in embedded system?

	Since embedded system has to continuously work and respond to the inputs, and some other jobs in loop. 
to make the system to run continuously for long time it has to be kept in infinite loop. 
Otherwise it will run only once and stops.



Ques 17: explain about ALU?
 ALU is present in the microprocessors  and microcontrollers. it will do the arithmetic and logic operations
 that is required to be done on instructions. The cpu is powerful if the design of the ALU good. It consumes
 more power and it releases more heat. This is why faster cpus consume more power releases more heat.

Interview Q & A 8

Interview Q & A 8



1. write a code for removing repeated digits in a number?
ex : number = 45678678 here the digits 6,7,8 has to be removed.



2. write a code to search the largest element in the array of your choice?



3. write a program to convert the integer string to number using atoi function.?


4. write a source code to find the sum of 1/3+1/5+1/7+ ....+1/n using recursive function?


5. write a code for linked list print function in reverse order?


6. what is the difference between address of variable and address of ponter variable, 
   explain using an example?


7. write a source code for insert a char/word/substring into a string?


8. can we return multiple values from the function explain with an example?


9.  what is the output for the below code?
	static int k= 8;
	int main()
	{
		if(-k)
		printf("%d", k);
		printf("error");
	}


10. what are the errors in the below source code?

int add();
int main()
{
	printf("function ",add());
}

int add()
{
	int x=5,y=4,z;
	z=x+y;
	printf("%d",z);
}


11. explain for the below code, the memory allocated is safe or not?

struct person
{
char per_name[10];
int per_age;
};
int main()
{
struct person *per;
per=(struct per*)malloc(sizeof(struct person));
free(per);
return 0;
}


12. explain the memory is safe for the below mentioned code?

struct person *per;
per=(struct person*)malloc(sizeof(struct person)*100);
char pername[] = "ptinstitute.in" ;
per = *pername;
free(per);
return 0;


13 what is the output for the below code explain?

char *name="ptinstitute.in";
char  name1[]="ptinstitute.in";
printf("%d %d ",strlen(name),strlen(name[]));
printf(" %d %d",sizeof(name++),sizeof(name[0]));


14. what is the output for the below program explain?
int main()
{
	int x=4,y=2,p,q,r;
	p=x||y;
	q=p&&x;
	r=p^q;
printf("%c %x %d",p,q,r);
return 0;
}


15. what is the output for the below code explain?

int main()
{
int p=4;
for( ;p++;printf("%d",p))
{
printf("ptinstitute.in");
}
return 0;
}

16. what is the output for the below program?

int main()
{
static int m=3;
main();
printf("%d",m++);
return 0;
}


answers:

10.  no errors. 
     output: 9 function

11. safe, because memory is allocated to pointer per.

12. here memory allocated to per , 
    then per = *pername         //it stores the 'p' in the per variable.
    we copying the ascii value of p to pointer p which gives runtime error.
    the allocated memory is not freed, so memory leakage happened here.

13. the prototype of strlen is
       size_t strlen ( const char * str );
    we need to pass the address of the string to find the length.
    in the program we passing strlen with name[], we are passing without index.
    we suppose to pass the address of the string. that is why it gives compile time error.
14. ascii character for 1, 1 0

15. it gives an lengthy loop, in the for loop we incrementing p++ in condition checking position,
    p++ doing continuously and the loop stops after p=0.

16 It gives an runtime error like stack over flow issue.
   here we are not exiting the recursive function main, it is calling continuously main recusively.



Interview Q & A 7

Interview Q & A 7



Ques 1. what is the priority inversion?
	If a low priority task holds the shared resource using semaphore that is required by the high priority task.
The high priority task has to wait till it completes the task. This is done by increasing the low priority 
task to high till it completes the task and once the finishes the task then it releases the resource to
high priority task. This is called priority inversion.


Ques 2. what are different memory segments of a program?

The memory segments are 

Stack segment:
	Here the local variables , arguments passed to the function, function return address, 
interrupt return address will be stored in stack. Stack grows from high memory to low memory.

Heap segment : This segment is used to allocate memory dynamically. It grows from low memory ot high.
we can allocate memory to pointers here.	
	
Uninitialised data segment:
Uninitialised data will be stored here.

Initialised data segment:
Initialised data will be stored here

Code segment:
The code and the constants will be stored here.


Ques 3. what is the difference between polling and interrupt?
	Polling : the system checks the IO devices is they need any cpu service and then do its service, this is called polling
        Interrupt: the IO device request the cpu to execute its service. this is called interrupt.

Some difference between interrupt and polling as follows:
Inerrupt:
	Device notify cpu that it needs cpu attention.
	Interrupt is a hardware mechanism
	An interrupt request line indicates the device needs a cpu service
        Interrupt handler services the device.
	The cpu is disturbed only when the device needs service, here the cpu cycles are saved.
        An inetrrupt can occur at any time
        Inerrupt is in efficient if the devices interrupting the cpu frequently

Polling:
	CPU checks in regular interval if any device is ready for service. 
	Polling is software mechanism.
	Command ready bit indicates the device is ready for service.
	CPU service the device
	Cpu has to check whether a device needs service regularly this wastes lots of cpu cycles.
        CPU Polls the devices at regular intervals. 
	polling becomes inefficient if the cpu finds the device rarly ready for the service.
	

Ques 4. what is semaphore?
 Semaphore is proposed by Dijkstra in 1965 is very significant technique, for solving the synchronisation issue in parallel processing.
Semaphore is simply nonnegative variable holding a number and shared between threads. 
This variable is used to solve critical section problem and to achieve process sychronisation mechanism.

There are two types of semaphores
  Binary semaphore: it is also called as mutex lock. when the thread want to use a resource then it take the
  semaphore uses the resource then it release the semaphore.

  Counting semaphore: it is used when the resources are more than one. If the thread wants to use the 
  resource then it take the semaphore and decrease the semaphore count, if another thread wants the resource then 
  it take the semaphore and decrement the count. After using the resource they release the semaphore and increment the count. 



Ques 5. what is mutex?

	Mutual exclusion object shortly called as Mutex.  Mutex is a locking mechanism. The thread uses the mutex, 
lock the mutex uses the resources then the same thread unlock the mutex. Only one process can use the mutex at a time.
Mutex allows the all threads to use mutex but one at a time.
The program requests the system to create a mutex object for a resource with an ID. when the thread wants to use the resource 
it will lock the mutex uses the resource then it unlocks the resource.


Ques 6. What is synchronous communication?
example communication happened between two people over the telephone.
communication happened with respect to clock signal is called synchronous communication.
synchronous devices require the clock has to be same in receiver and transmitter.
The receiver can sample the signal at the same time interval as the transmitters send the data.


Ques 7. what is watchdog timer?

the watchdog timer continuously counts and some malfunction occured in the system it will reset the system.
The watchdog timer has to be serviced before the watchdog timer expires. if some malfunction occured in system, then it wouldnot service
the watchdog timer. then it will reset the system.


Ques 8. Find the size of the structure ?

struct st1{
int var1;
char ch1;
int var2;
float f1;
};

Ans : 16 bytes.
 In 32 bit system the memory is allocaed in 32 bit size. To make the memory accessing faster it write/reads 32 bit data at a time.
thats why it allocates 4 bytes to char.and others to 4 bytes as usual. in case of char one byte for data and other 3 bytes store garbage.
to effectively use the memory all chars to be placed at one place, other 4 byte sized datatypes at another location.
we can pack the datatypes using #pragam pack(1) defination above the main function.


Ques 9. Convert Binary to decimal for the below numbers?
11001111

ans: 
1 * 2^0 = 1 *1 = 1
1 * 2^1 = 1 *2 = 2
1 * 2^2 = 1 *4 = 4
1 * 2^3 = 1 *8 = 8
0 * 2^4 = 1 *0 = 0
0 * 2^5 = 1 *0 = 0
1 * 2^6 = 1 *64 = 64
1 * 2^7= 1 *128 = 128
------------------------
                  207


Ques 10. find the size for the following?

char arr[6];
int iarr[8];
int *p;

the sizeof arr is 6 bytes
the sizeof iarr is 32 bytes
the sizeof p is 4 bytes


Ques 11. write the truth table for xor gate & or gate?

the truth table for XOR gate:
A   B   O/p
1   1    0
0   0    0
1   0    1
0   1    1

the truth table for OR gate:
A   B   O/p
1   1    1
0   0    0
1   0    1
0   1    1



Ques 12. what is the output for the below code?

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

int main()
{
    int  arr[8] ={0,1,2,3,4,5,6,7,8};
    int i;
    for(i=2; i<8 ;i++)
        arr[arr[i]] = arr[i];
    for(i=0; i<8 ; i++)
        printf("%d ", i, arr[i]);
    return 0;
}

ans: 0 1 2 3 4 5 6 7

Interview QA5

Interview QA5



Ques 1. what is the use of voltile qualifier?

If the variable is declared as volatile , the variable may updated by external program or hardware.
The volatile variable is not optimized by the compiler.
The volatile always read from memory instead of from registers.


Ques 2. what is the use of const keyword?
If the variable is declared as const. then the value of the varible would not be changed by the program.
it is not updated by the user.

const int MAX = 78;
const char STR[10] = "welcome";



Ques 3. what is the use of static variables?

If the variable is declared as static globally, then it is accessible only inside the file where it is declared.
we could not access outside the file.

If the local varible is declared as static inside the function then it is accessible inside the function only.
The varible is initialised only in first call to function. In the next call of the function static variable hold
the previous value will not initialise .

The static variable stored in memory.
The life of the variable is till the program is running.



Ques 4. write a c program to validate the user name and password?

#include <stdio.h>
#include <stdlib.h>
int main()
{
    char username[4][20]={ "user1", "user2", "user3", "user4"};
    char password[4][20] = {"password123", "password456", "password678", "password567"};
    char usern[20], passwordn[20];
    int i=0, j=0, k=0, uname=0, passw=1;

    while(1)
    {
    printf("\n enter the username to login:");
        scanf("%s", usern);
    printf("\n enter the password to login:");
        scanf("%s", passwordn);

    for(i=0; i<4; i++)
    if(strcmp(username[i], usern) == 0)
    {
        uname=1;
            for(j=0; j<4; j++)
            if(strcmp(password[j], passwordn) == 0)
            {
                printf("\n both username and password correct.");
                passw=1;
                break;
            }

    }
    if(uname==0)
        printf("\n entered the wrong username");
    if(passw ==0)
        printf("\n entered the wrong password.");
    else
        break;
    k++;
    if(k==3)
    {
     printf("\n you are exceeded 3 chances to enter password and username.");
     break;
    }
    }
    return 0;
}
 


5. what is optimization in c program?

Optimization is the method of improving the code efficiency and quality.
c program can become less in size, occupies less memory space, speed execution is more. 

The methods of code optimization are:
1. Optimization in loops: 
1.1 unroll small loops: 
 	Instead of calculating and storeing the known constant values, we can directly calculate and initialise.

     factorial number calculation:

program1:
int main()
{
    int fct[6];
	int i;
        fct[0] =1;
	for(i=1; i<6; i++)
		{
		    fct[i] = fct[i-1] *i;		
		}
1, 2 6 24 120
    return 0;
}


program 2: modified program of program1
int main()
{
    int fct[6] = {1, 2, 6, 24, 120};

    return 0;
}

1.2. Avoid calculation in loops:
   we should avoid calculating the in loops which will give same value in all iterations.

example1:
int main()
{
    int x=3, y=4, z=6, m=4;
    int g[100], p;

    for(p=0; p<100; p++)
        g[p] = (x*y+z*m) * p;

    return 0;
}


optimized code of example1:
int main()
{
    int x=3, y=4, z=6, m=4;
    int g[100], p;

    int temp= (x*y+z*m);
    for(p=0; p<100; p++)
        g[p] =  temp* p;

    return 0;
}

1.3. Avoid pointer dereference in loop: 
   since it creates lots of work in memory to access the data each time, so dereference 
   before the loop using some temporary variable.

example1:
int main()
{
    int x=0, p;
    int *q=&x;

    for(p=0; p<100; p++)
        *q = *q+p;
    printf("\n %d ", *q);

    return 0;
}

optimized code of example1:

int main()
{
    int x=0, p;
    int *q=&x;
    int t=*q;

    for(p=0; p<100; p++)
        *q = *q+p;
    *q=t;
     printf("\n %d ", *q);

    return 0;
}

1.4. user register storage class for loop variables: it will increase the speed of accessing the variables.

example1:
int i, temp=0;
for(i=0; i<100; i++)
{
   temp= temp+i;
}

optimized code for example1:
int temp=0;
register int i=0;
for(i=0; i<100; i++)
{
   temp= temp+i;
}

2. Increasing Speed of mathemetical calculation:

2.1 avoid not required division operations, since division operation decreases the speed of execution.

	int x=2,y=3,z=4,m=5,n=6;
	x=y+z+(x/y/z/m)+n;

    we can make modify it as
        x = y+z+(x/(y*z*m)) + n ;  

2.2 Multiplication and Division by power of 2 : 
we can use << for multiplication by 2 and we can use >> for division by 2. 
These shift operations are faster than multiplication and division operation so we can 
use them. the compiler will optimize the code incase of complex expression code
it is advised to do bitshifting.

multiplying by 6 : m= (m<<1)+ (m<<2)
multiplying by 7: m= m<<3 - m
devide by 4      : m = m>>2

2.3 : simplying the complex code expression: 
by simplyfying the expression we can reduce the number of mathematical computations.

Ex:
     z=  a*b +a*b*c+ a*b*c*d 
     z= a*b*(c*(1+d))
here we reduced the 6 multiplication 3 addtion to 3 multiplication and 1 addition.

3 Optimizing the switch statements:

 In c switch statements if case labels are continuous then the compiler creates a jump table and it is faster.
 If it is not then it will creates a if else statements. Compiler will put the most frequent conditions first and
 rarely used at later. so keep the most used cases first and rarely used labels later.

 
ex1: 
 switch(exp)
{
case x:
        different expression
	break;
case y:
        different expression
	break;
case z:
	common statements1;
        different expression
	common statements2;
	break;
case m:
	common statements1;
        different expression
	common statements2;
	break;
case n:
        different expression
	break;
}

modified of example1 for code optimization:

 switch(exp)
{
case x:
        different expression
	break;
case y:
        different expression
	break;
case z:
case m:
common statements1;
switch(exp)
	{
        different expression
	break;
case m:
        different expression
	break;
}
	common statements2;
case n:
        different expression
	break;
}

4. prefer int instead of char or short:
 since the char are converted to int then do the calculation after doing the calculation
 it again converted to char.
 if it doing in a loop it affects lot on performance.

5. pre-increment is preferred than post -increment
  
In pre increment the value is just increment by 1 and copies the value to variable location. 
In post increment the value is copied to temporary variable then it inremented and then it copies the value to variable. 

6. order of expression evaluation:

   ex1 : A || B   Here if A is true then no need to check the B so first we have to keep the exprission most of the times evaluates to true.
   ex2 : A && B   Here if A is false then no need to check the B so first we have to keep the exprission most of the times evaluates to false.


6. can we pass structure be passed by value to a function?

yes, we can pass structure to function by value.

#inclue<stdio.h>
#include <stdlib.h >
struct s{
int d;
}s2;

fun(struct s s2)
{
printf("%d \n ", s2.d);
}

int main()
{
    s2.d=45;
fun(s2);
    return 0;
}


7. why cannot we pass arrays to function by value?
	since array have many elements so individual elements we can pass,
     but without the address we cannot access all the elements. so we cannot pass arrays by value to function.

8. difference between macro and inline funtion?

difference in evaluation:
  - the macro is replaced by it code during preprocessing
  - the inline function is parsed by the compiler.

 - In macro the expression passed as arguments are copied to the variables.
 - in inline the expression passed as arguments are evaluated then copied to variables.

#include

#define CUBE(M) M*M*M
inline int cube(int m)
{
	return m*m*m;
}

int main()
{
	printf(" %d",CUBE(1+2));
	printf(" %d",cube(1+2));
	return 0;
}

output:
7 27

for macro it become  1+2*1+2*1+2 = 1+2+2+2= 7
for inline function  3*3*3 = 27

- macro would not check the type of the arguments
- inline funtion check the type checking for arguments passed.

- macro always expanded by the preprocessor 
- inline function is depend on the compiler decesion to replace it by its code.



9. is the recursive function can be inline?

The compiler decides whether the declared function is inline or it can be treated as normal  function.
The recursive functions are treated as normal function by the compiler even though we declared it as inline.

#include <stdio.h>

int cnt=0;
inline int cube(int m)
{
    cnt++;
    if(cnt<=3)
        cube(m);
    else
    return m*m*m;
}

int main()
{
    int x;
    x=cube(2);
    printf("\n %d",x);
    return 0;
}


10. #define abc(x,y) x##y concatenates but abc( abc(x,y)) gives warning why?

abc(x,y) gives xy which substituted in the inside function .
For the outer function will get 1 argument instead of two , so it gives compiler error.



11. can we declare volatile variable?
 yes we can declare. the variable is constant for the program it is declared.
 but the external program or hardware can change it.

Interview Q & A 6

Interview Q & A 6



Ques 1. write a c program to print "Goodmorning" without using ; ?

ex1:
#include <stdio.h>
#include <stdlib.h>
int main()
{
if(printf("\n Goodmorning"))
}

ex2:
#include <stdio.h>
#include <stdlib.h>
int main()
{
while(!printf("\n Goodmorning")){}
}

ex3:
#include <stdio.h>
#include <stdlib.h>
int main()
{
switch(!printf("\n Goodmorning")){}
}


Ques 2. exchange / swap two numbers without using third variable?

program 1:

#include <stdio.h>
#include <stdlib.h>
int main()
{
 int m,n;
 m=2;
 n=5;
 m = m+n;
 n = m-n;
 m = m-n;
 printf("\n m =%d n=%d ", m,n);
    return 0;
}

program 2:
int main()
{
 int m,n;
 m=2;
 n=5;
 m = m+n-(n=m);

 printf("\n m =%d n=%d ", m,n);
    return 0;
}
program 3:
int main()
{
 int m,n;
 m=2;
 n=5;
 m=m^n;
 n=m^n;
 m=m^n;
 printf("\n m =%d n=%d ", m,n);
 return 0;
}
program 4:
int main()
{
 int m,n;
 m=2;
 n=5;
 m = m - ~n - 1;
 n = m + ~n + 1;
 m = m + ~n + 1;

 printf("\n m =%d n=%d ", m,n);
    return 0;
}




Ques 3. what is dangling pointer in c?

Initially a pointer has been pointing some variable location, later the pointer pointing to the memory location
is deleted. but the pointer still pointing to same memory location.
This pointer is called dangling pointer. the error is called dangling pointer error.

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

int main()
{
 int m=34;
 int *p=(int*)malloc(4);
 *p=m;
 free(p);
 printf("\n m =%d ", *p);
    return 0;
}



Ques 4. what is the output for the below code?

#include <stdio.h>
#include <stdlib.h>
int * fun()
{
   int x=44;
    return &x;
}

int main()
{
 int m=34;
 int *p;
 p =fun();

 printf("\n m =%d ", *p);
 return 0;
}

Ans: runtime error/ garbage value prints, since the scope of the local variable 
x is only inside the function fun(), so we can get the address of this variable.
so this is called dangling pointer error.

solution: if we make x as static then it works.



Ques 5. what is wild pointer in c?

A pointer which is not initialised is called wild pointer, 
it returns the some random address and garbage value.

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

int main()
{
  int *p;

 printf("\n p =%u =%d", p,*p);
 return 0;
}

output:  it gives garbage value or prints nothing. NULL pointer means pointing to memory location 0, 
wild pointer means it pointing to some unknown location and gives some garbage value.



Ques 6. what is the advantage and disadvantage of arrays in c?

The advantage : once the array is declared the memory is allocated and we can access each element by using the array indexes.
                it can store elements of the same data type.
               we can declare array for different data types like int , float, struct, union.
               we can initialise the array while declaration.
		an array pointing to the address of the other elements is called pointer array.
disadvantage: if the array index goes out of boundary then there is a huge mistake, some wanted data will be 
              overwritten or the program may crash.
              if array size is more than the usable then the remaining memory is wasted.


array declaration example:
int arr[4];
char str[33];
short int sarr[34];
float fr[12];
int (*funptr[4])();
long *larr[21];
double **p[5];



Ques 7. what is the output for the below code?
#include <stdio.h>
#include <stdlib.h>

int main()
{
 double d1=33.44, d2=33.55, d3=66.78;
 double *dptr[3] ={&d1, &d2, &d3 };

 printf("\n %e", *dptr[0]);
 return 0;
}

ans : 3.344 e+001

Here dptr is a pointer array  it points to the elements d1,d2,d3.



Ques 8. explain about do while loop and write a program?
	do while loop we can use to execute the code in the loop before checking the condition.
	it executes the loop atleast one time.

#include <stdio.h>
#include <stdlib.h>
int main()
{
 int i;
 do {
    printf("\n this is do while loop");
 } while(i !=0);
 return 0;
}



Ques 9. what is the output for the below code?

#include <stdio.h>
#include <stdlib.h>
int i;
i=45;
main()
{
printf("\n %d", i);
return 0;
}

ans:
it gives compilation error, since assignment outside main function is not allowed.



Ques 10. what is the output for the below code?

#include <stdio.h>
#include <stdlib.h>
static int i=10;
int main()
{
for(i=0; i<5; i++)
{
    static int a=3;
    printf("%d ", a++);
}
 return 0;
}

ouput : 3 4 5 6 7

static variable initialises only once, so the variable a prints 3,4,5,6,7



Ques 11. what is the output for the below code?

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

static int i=10;
int main()
{
{
    static int a=3;
    printf("%d ", a++);
}
    printf("%d ", a);
 return 0;
}

output:
it gives compiler error because the static variable declared within the block is local to the block.
we cannot access outside of it.



Ques 12. what is the output for the below code?

#include <stdio.h>
#include <stdlib.h>
static int a=10;
void fun();
int main()
{

   printf("%d ", a++);
   printf("\nmain b= %d",b);
 return 0;
}
int b=323;
void fun()
{
printf("\n b= %d",b);
}

output: compiler error since the global variable b has to be declared above the main function.



Ques 13. what is the output for the below code in two different files file1.c and file2.c?

//file1.c

#include <stdio.h>
#include <stdlib.h>
extern int sum();
static int i=3, j=5;
int main()
{
    int p;
    p=sum();
    printf("%d ", p);
    return 0;
}

//file2.c

#include <stdio.h>
#include <stdlib.h>
extern int sum();
static int i=3, j=5;
int main()
{
    int p;
    p=sum();
    printf("%d ", p);
    return 0;
}

output:
It gives compiler error, since the global static variables declared i,j are only accessed in file1.c file, 
we cannot access it in file2.c file.
global static variables declared accessed only in the file where they are declared.



Ques 14. what is the output for the below code?

#include <stdio.h>
#include <stdlib.h>
int main()
{
int k=0;
{
   static int p=5;

PRINT:
    printf(" %d", p);
    p++;
    k++;
}
    if(k<4)
        goto PRINT;
    return 0;
}

output|: 5 6 7 8

The life of static varible still exists the control come out and go inside the block.



Ques 15. what tells the prototype of a function ?

prototype of a function is declaration of a function.
it tells the return type of the function,
it tells the input arguments the function takes.
it tells the function name

ex:
int fun(float, char);


Ques 16. what is the output for the below code?

#include <stdio.h>
#include <stdlib.h>
int main()
{
const int k=20;
int *p;
p=&k;
*p=34;

printf("%d", *p);
    return 0;
}

output: 34
we can modify the constant variables in c using pointers.



Ques 17. what is the output for the below code?

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

int search(char);
int (*fun())(char c);

int main()
{
    int m=0;
    int (*p)(char);
    p=fun();
    m=(*p)('h');
    printf("%d", m);
    return 0;
}

int search(char d)
{
    return d;
}

int (*fun())(char g)
{
    return search;
}


output:
104

p=fun()
m=(*p)('h')
m=(*fun())('h') // since p=fun();
m= (*&search())('h')  // since fun returns &search
m= search('h')
m=104.



Test your C skills

Interview Q & A 4



Ques 1. what happens for the below code since the array subscrit is more
 than the size of the array?

#include <stdio.h>
#include <stdlib.h>
int main()
{
	int arr[3] ={3,4,5};
	arr[5]=4343;
}

options:
A. The arr[5] hold the value no issue.
B. Some valid data will be overwritten and the program may crash.
C. compiler error
D. the array size increases


Ques 2. what is the output for the below code?
#include <stdio.h>
#include <stdlib.h>
int main()
{
    int m=1, n=1;
    for(; m; printf("%d %d\n", m++, n), m=n++<=2);   

    return 0;
}

options:
A. 1 1 1 2 1 3
B. 1 1 2 2 3 3
C. 2 1 3 2 4 2
D. 1 1 0 2 0 3
 

Ques 3. which of the below options is correct about the uart communication?

options:
A. Uart reads the buffer register and transmit data in parallel.
B. Transmit data in buffer register, UART adds start bit, parity, stop bits to the data, then tranmit data in parallel.
C. Transmit data in buffer register, UART adds start bit, parity, stop bits to the data, then tranmit data in parallel.
D. Transmit data in buffer register, UART adds start bit, parity, stop bits to the data, then tranmit serially.


Ques 4. what is the output for the below code?
#include <stdio.h>
#include <stdlib.h>
int main()
{
    enum color{red, green, blue}s;
    printf("%d\n",sizeof(s));
    return 0;
}

options:
A. 2
B. 4
C. 1
D. 8


Ques 5. what is the output for the below code?
#include <stdio.h>
#include <stdlib.h>
int main()
{
    int x=1, y=3, z=8, m=0, n=2;
    x = (x || (y=z)) && (m || (y=n));
    printf("%d %d %d %d %d",x,y,z,m,n);

    return 0;
}

options:
A. 1 2 0 8 2 
B. 1 0 2 2 8
C. 1 2 8 0 2
D. 0 2 2 1 8


Ques 6. what is the output for the below code?
#include <stdio.h>
#include <stdlib.h>
int add( int x, int y)
{
    return x+y;
}

int sub( int x, int y)
{
    return x-y;
}

int mul( int x, int y)
{
    return x*y;
}

int divide( int m, int n)
{
    return m/n;
}

int (*f[4])(int x, int y)={add, sub, mul,divide};

int main()
{
 int x=3, y=2, i;

 for(i=0; i<=3; i++)
    printf("%d ", (*f[i])(x, y));

    return 0;
}


options:
A. compiler error
B. 5 1 6 1
C. runtime error
D. 5 1 6 1.5


Ques 7. what are the features of the function?

  - code is more readable.
  - testing the code is easier
  - recursive call can be done for functions
  - each functionality can be kept seperately


Ques 8. what is the output for the below code?

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

int * fun();

int main() {
      int *q;
      q=fun();
      printf("%d",*q);
      return 0;
    }

int * fun() {
      int g=25;
      g--;
      g--;
      return &g;
      }

options:
A. 23
B. 25
C. compiler error
D. runtime error


Ques 9. How the build process happens in c program?

options:
A. Preprocessing, compilation, linking
B. compilation, Preprocessing, linking
C. linking, Preprocessing , compilation
D. none of the above


Ques 10. when we found the undefined function error while building the c program?

options:
A. linking
B. preprocessing
C. compilation
D. none of the above


Ques 11. using volatile keyword for the below code is valid ?

#include <stdio.h>
#include <stdlib.h>
volatile int m=3;
    int main() {
      int h=3,i;
      for(i=0; i<5; i++)
        h=m;
      return 0;
    }

options:
A. since it is in loop not valid
B. it is valid the value of m may change
C. it gives compiler error
D. none of the above


Ques 12. if one wants to transmit data to 4 receivers within the distance of 50 feet with a speed of 6mbs
so which protocol is suitable for this?

options:
A. rs232
B. rs245
C. rs422
D. rs485


Ques 13. which of the following is correct?

options:
A. SPI speed is lesser than I2C and UART
B. SPI uses the chip select signals to select the slaves
C. Multi master is possible in SPI communication
D. SPI will communicate with one slave



Answers

1. B 2. A 3. D 4. B 5. C 6. B 8. D 9. A 10. A 11. B 12. C 13. B

En-Query

Your Name*
Subject*
Phone Number*
Email Address*

Message*