Tuesday, March 09, 2010

NETWORK SECURITY Honeypot Solutions




NETWORK SECURITY






Honeypots are an exciting new technology.In the past several years there has been growing interest in exactly what this technology is and how it works. The purpose of this paper is to introduce you to honeypots and demonstrate their capabilities.
A honeypot is a security resource whose value lies in being probed, attacked, or compromised. The key point with this definition is honeypots are not limited to solving only one problem; they have a number of different applications. To better understand the value of honeypots, we can break them down into two different categories:
1.Production
2.Research..
A properly constructed honeypot is put on a network, which closely monitors the traffic to and from the honeypot. This data can be used for a variety of purposes
 Forensics - analyzing new attacks and exploits
 Trend analysis - look for changes over time of types of attacks, techniques, etc
 Identification - track the bad guys back to their home machines to figure out who they are
 Sociology - learn about the bad guys as a group by snooping on email, IRC traffic, etc which happens to traverse the honeypot.Traditionally, honeypots have been physical systems on a dedicated network that also contains multiple machines for monitoring the honeypot and collecting logs from it.
This paper throws further light on the advantages and the disadvantages of honeypots and on some honeypots solutions. For sure, Honeypots are a boon to the field of Network Security.






Introduction:
Many people have their own definition of what a honeypot is, or what it should accomplish. Some feel its a solution to lure or deceive attackers, others feel its a technology used to detect attacks, while other feel honeypots are real computers designed to be hacked into and learned from. In reality, they are all correct.
Definitions and Value of Honeypots:
Over the past several years there has been a growing interest in honeypots and honeypot related technologies. Honeypots are not a new technology; they were first explained by a couple of very good papers by several icons in computer security. There are a variety of misconceptions on what a honeypot is, how it works, and how it adds value. It is hoped this paper helps clear up those issues.
We may define a honeypot as "a security resource whose value lies in being probed, attacked or compromised." This means that whatever we designate as a honeypot, it is our expectation and goal to have the system probed, attacked, and potentially exploited. Keep in mind, honeypots are not a solution. They do not 'fix' anything. Instead, honeypots are a tool. How you use that tool is up to you and depends on what you are attempting to achieve. A honeypot may be a system that merely emulates other systems or applications, creates a jailed environment, or may be a standard built system. Regardless of how you build and use the honeypot, it's value lies in the fact that it is attacked.
We will break honeypots into two broad categories
1.Production Honeypot
2.Research Honeypot
Production Honeypot:
The purpose of a production honeypot is to help mitigate risk in an organization. The honeypot adds value to the security measures of an organization. Traditionally, commercial organizations use production honeypots to help protect their networks. It adds value to the security of production resources. Lets cover how production honeypots apply to the three areas of security, Prevention, Detection, and Reaction.

Prevention:
Honeypots will not help keep the bad guys out. What will keep the bad guys out is best practices, such as disabling unneeded or insecure services, patching what you do need, and using strong authentication mechanisms. It is the best practices and procedures such as these that will keep the bad guys out. A honeypot, a system to be compromised, will not help keep the bad guys out. In fact, if incorrectly implemented, a honeypot may make it easier for an attacker to get in.
Some individuals have discussed the value of deception as a method to deter attackers. The concept is to have attackers spend time and resource attacking honeypots, as opposed to attacking production systems. The attacker is deceived into attacking the honeypot, protecting production resources from attack. Deception may contribute to prevention, but you will most likely get greater prevention putting the same time and effort into security best practices.
Detection:
While honeypots add little value to prevention, they add extensive value to detection. For many organizations, it is extremely difficult to detect attacks. Intrusion Detection Systems (IDS) are one solution designed for detecting attacks. However, IDS administrators can be overwhelmed with false positives. False positives are alerts that were generated when the sensor recognized the configured signature of an "attack", but in reality was just valid traffic. The problem here is that system administrators may receive so many alerts on a daily basis that they cannot respond to all of them. Also, they often become conditioned to ignore these false positive alerts as they come in day after day.The very IDS sensors that they were depending on to alert them to attacks can become ineffective unless these false positives are reduced. This does not mean that honeypots will never have false positives, only that they will be dramatically less than with most IDS implementations.
Another risk is false negatives, when IDS systems fail to detect a valid attack. Many IDS systems, whether they are signatures based, protocol verification, etc can potentially miss new or unknown attacks. It is likely that a new attack will go undetected by currently IDS methodologies. Also, new IDS evasion methods are constantly being developed and distributed. It is possible to launch a known attack that may not be detected, such as with K2's ADM Mutate. Honeypots address false negatives as they are not easily evaded or defeated by new exploits. In fact, one of their primary benefits is that they can most likely detect when a compromise occurs via a new or unknown attack by virtue of system activity, not signatures. Administrators also do not have to worry about updating a signature database or patching anomaly detection engines. Honeypots happily capture any attacks thrown their way. As discussed earlier though, this only works if the honeypot itself is attacked.
Reaction:
Often when a system within an organization is compromised, so much production activity has occurred after the fact that the data has become polluted. Incident response team cannot determine what happened when users and system activity have polluted the collected data.
The second challenge many organizations face after an incident is that compromised systems frequently cannot be taken off-line. The production services they offer cannot be eliminated. As such, incident response teams cannot conduct a proper or full forensic analysis.
Honeypots can add value by reducing or eliminating both problems. They offer a system with reduced data pollution, and an expendable system that can be taken off-line. For example, let’s say an organization had three web servers, all of which were compromised by an attacker. However, management has only allowed us to go in and clean up specific holes. As such, we can never learn in detail what failed, what damage was done, is there attacker still had internal access, and if we were truly successful in cleanup.
However, if one of those three systems were a honeypot, we would now have a system we could take off-line and conduct a full forensic analysis. Based on that analysis, we could learn not only how the bad guy got in, but also what he did once he was in there. These lessons could then be applied to the remaining webservers, allowing us to better identify and recover from the attack.
Research Honeypot:
One of the greatest challenges the security community faces is lack of information on the enemy. Questions like who is the threat, why do they attack, how do they attack, what are their tools, and possibly when will they attack? It is questions like these the security community often cannot answer. For centuries military organizations have focused on information gathering to understand and protect against an enemy. To defend against a threat, you have to first know about it. However, in the information security world we have little such information.
Honeypots can add value in research by giving us a platform to study the threat. What better way to learn about the bad guys then to watch them in action, to record step-by-step as they attack and compromise a system. Of even more value is watching what they do after they compromise a system, such as communicating with other blackhats or uploading a new tool kit. It is this potential of researches that is one of the most unique characteristics of honeypots. Also, research honeypots are excellent tools for capturing automated attacks, such as auto-rooters or Worms. Since these attacks target entire network blocks, research honeypots can quickly capture these attacks for analysis.
In general, research honeypots do not reduce the risk of an organization. The lessons learned from a research honeypot can be applied, such as how to improve prevention, detection or reaction. However, research honeypots contribute little to the direct security of an organization. If an organization is looking to improve the security of their production environment, they may want to consider production honeypots, as they are easy to implement and maintain. If organizations, such as universities, governments, or extremely large corporations are interested in learning more about threats, then this is where research honeypots would apply. The Honeynet Project is one such example of an organization using research honeypots to capture information on the blackhat community.

Honeypot Solutions:
Now that we have been discussing the different types of honeypots and and their value, lets discuss some examples.Simply put, the more an attacker can interact with a honeypot, the more information we can potentially gain from it, however the more risk it most likely has.The more a honeypot can do and the more an attacker can do to a honeypot, the more information can be derived from it. However, by the same token, the more an attacker can do to the honeypot, the more potential damage an attacker can do. For example, a low interaction honeypot would be one that is easy to install and simply emulates a few services. Attackers can merely scan, and potentially connect to several ports. Here the information is limited (mainly who connected to what ports when) however there is little that the attacker can exploit. On the other extreme would be high interaction honeypots. These would be actual systems. We can learn far much more, as there is an actual operating system for the attacker to compromise and interact with, however there is also a far greater level of risk, as the attacker has an actual operating system to work with. Neither solution is a better honeypot. It all depends on what you are attempting to achieve. Remember that honeypots are not a solution. Instead, they are a tool. Their value depends on what your goal is, from early warning and detection to research. Based on 'level of interaction', lets compare some possible honeypot solutions.
For this article, we will discuss four honeypots. There are a variety of other possible honeypots, however this selection covers a range of options. We will cover BackOfficer Friendly, Specter, Honeyd, and Homemade honeypots. This article is not meant to be a comprehensive review of these products. It only highlights some of their features. Instead, It hopes to cover the different types of honeypots, how they work, and demonstrate the value they add and the risks involved.
• BackOfficer Friendly:
BOF (as it is commonly called) is a very simple but highly useful honeypot.BOF is a program that runs on most Window based operating system. All it can do is emulate some basic services, such as http, ftp, telnet, and mail. Whenever some attempts to connect to one of the ports BOF is listening to, it will then log the attempt. BOF also has the option of "faking replies", which gives the attacker something to connect to. This way you can log http attacks, telnet brute force logins, or a variety of other activities. It can monitor only a limited number of ports, but these ports often represent the most commonly scanned and targeted services.
• Specter:
Specter is a commercial product similar to BOF in that it emulates services, but it can emulate a far greater range of services and functionality. In addition, not only can it emulate services, but emulate a variety of operating systems. Similar to BOF, it is easy to implement and low risk. Specter works by installing on a Windows system. The risk is reduced, as there is no real operating system for the attacker to interact with. For example, Specter can emulate a webserver or Telnet server of the operating system of your choice. When an attacker connects, it is then prompted with an http header or login banner. The attacker can then attempt to gather web pages or login to the system. This activity is captured and recorded by Specter, however there is little else the attacker can do. There is no real application for the attacker to interact with, instead just some limited, emulated functionality. Specter value lies in detection. It can quickly and easily determine who is looking for what. As a honeypot, it reduces both false positives and false negatives, simplifying the detection process.
• Home made Honeypots:
Another common honeypot is homemade. These honeypots tend to be low interaction. Their purpose is usually to capture specific activity, such as Worms or scanning activity. These can be used as production or research honeypots, depending on their purpose. Once again, there is not much for the attacker to interact with, however the risk is reduced because there is less damage the attacker can do. One common example is creating a service that listens on port 80 (http) capturing all traffic to and from the port. This is commonly done to capture Worm attacks. One such implementation would be using netcat, as follows:
netcat -l -p 80 > c:\honeypot\worm
In the above command, a Worm could connect to netcat listening on port 80. The attacking Worm would make a successful TCP connection and potentially transfer its payload. This payload would then be saved locally on the honeypot, which can be further analyzed by the administrator, who can assess the threat of the Worm.

• Honeyd:
Honeyd is an extremely powerful, OpenSource honeypot. Designed to run on Unix systems, it can emulate over 400 different operating systems and thousands of different computers, all at the same time. Honeyd introduces some exciting new features. First, not only does it emulate operating systems at the application level, like Specter, but it also emulates operating systems at the IP stack level. This means when someone Naps your honeypot, both the service and IP stack behave as the emulated operating system. Currently no other honeypot has this.Second, Honeyd can emulate hundreds if not thousands of different computers all at the same time. While most honeypots can only emulate one computer at any point in time, Honeyd can assume the identity of thousands of different IP addresses. Third, as an OpenSource solution, not only is it free to use, but it will exponentially grow as members of the security community develop and contribute code.

Value of Honeypots:
Honeypots have certain advantages (and disadvantages) as security tools. It is the advantages that help define the value of a honeypot. The beauty of honeypots lies in its simplicity. It is a device intended to be compromised, not to provide production services. This means there is little or no production traffic going to or from the device. Any time a connection is sent to the honeypot, this is most likely a probe, scan, or even attack. Any time a connection is initiated from the honeypot, this most likely means the honeypot was compromised. As there is little production traffic going to or from the honeypot, all honeypot traffic is suspect by nature. Now, this is not always the case. Mistakes do happen, such as an incorrect DNS entry or someone from accounting inputting the wrong IP address. But in general, most honeypot traffic represents unauthorized activity.
Advantages :
The advantages of honeypots include:
 Small Data Sets: Honeypots only collect attacks or unauthorized activity, dramatically reducing the amount of data they collect. Organizations that may log thousands of alerts a day may only log a hundred alerts with honeypots. This makes the data honeypots collect much easier to manage and analyze.
 Reduced False Positives: Honeypots dramatically reduce false alerts, as they only capture unauthorized activity.
 Catching False Negatives: Honeypots can easily identify and capture new attacks never seen before.
 Minimal Resources: Honeypots require minimal resources, even on the largest of networks. This makes them an extremely cost effective solution.
 Encryption: Honeypots can capture encrypted attacks.
 In-depth Information: Honeypots can capture data no other technology can, including the identity of your attacker, their motives, and whom they are potentially working with.
 IPv6: IPv6 is the new IP protocol that represents the future of the Internet and IP based networking. Most technologies cannot detect, capture, nor analyze IPv6 based traffic. Honeypots are one of the few technologies that can operate in any IPv6 (or IPv6 tunneled) environments.
Disadvantages:
• Single data point:
Honeypots all share one huge drawback; they are worthless if no one attacks them. Yes, they can accomplish wonderful things, but if the attacker does not send any packets to the honeypot, the honeypot will be blissfully unware of any unauthorized activity.
• Risk:
Honeypots can introduce risk to your environment. As we discuss later, different honeypots have different levels of risk. Some introduce very little risk, while others give the attacker entire platforms from which to launch new attacks. Risk is variable, depending on how one builds and deploys the honeypot.
It is because of these disadvantages that honeypots do not replace any security mechanisms. They can only add value by working with existing security mechanisms. Now that we have reviewed the overall value of honeypots, lets apply them to security.
Conclusion :
A honeypot is just a tool. How we use that tool is up to us. There are a variety of honeypot options, each having different value to organizations. We have categorized two types of honeypots, production and research. Production honeypots help reduce risk in an organization. While they do little for prevention, they can greatly contribute to detection or reaction. Research honeypots are different in that they are not used to protect a specific organization. Instead they are used as a research tool to study and identify the threats in the Internet community. You will have to determine what is the best relationship of risk to capabilities that exist for you. Honeypots will not solve an organization's security problems. Only best practices can do that. However, honeypots may be a tool to help contribute to those best practices.



EXAMPAPERS123.BLOGSPOT.COM

Mobile Computing Mobile Voice Communication

Mobile Computing Mobile Voice Communication
“MOBILE COMPUTING” means computing done by intermittently-connected users who access network resources. It requires a wireless medium such as cellular radio, radio nets and low-orbit satellites. It incorporates wireless adapters using cellular telephone technology to connect portable computers with the cabled network.
Mobile voice communication is widely established throughout the world and has had a very rapid increase in the number of subscribers to the various cellular networks over the last few years. An extension of this technology is the ability to send and receive data across these cellular networks. This is the principle of mobile computing.
Mobile data communication has become a very important and rapidly evolving technology as it allows users to transmit data from remote locations to other remote or fixed locations. This proves to be the solution to the biggest problem of business people on the move-mobility.
Our mobile system architecture supports applications by a middleware stub. Mobile Computing evolved during the last few years as a result of shrinking portables and growing wireless networks. It enlarges the usability of computers, but raises demanding challenges.
INTRODUCTION
The architecture consists of a Mobility Service Architecture, describing the way we implement our mobility services in a computer system, and a Mobility Environment Architecture describing how data are transmitted between computers in mobile environments and what tasks the different stations fulfill in our architecture
Mobility Services Architecture:
Mobility services can be classified into three groups. First there are services designed to overcome common restrictions of mobile computing, which arise mainly from the slowness, insecurity and instability of wireless or analogous connection lines utilized by the mobile user. These services are called common mobility services (CMS). Examples are connection management, caching or encryption services. The second group of services handles the management and administration of mobile users moving around and connecting their portables to networks at different places. These mobility management services (MMS) include tasks such as the authentication of users, accounting and billing
issues or profiling of the users' habits. The tasks necessary to adapt certain existing applications to mobile usage are implemented by high level services, which are called special mobility services (SMS). Special mobility services adapt existing services to the mobile conditions. For example to allow remote database access over a wireless connection line one has to take special care of possible frequent connection losses especially in the context of the state of the database. Viewing services as distinct building blocks, we are able to sketch architecture for a "mobility services enhanced system".
Mobility Environment Architecture:
To overcome restrictions in mobile computing the above architecture was designed; the architecture consists of the following parts: The network environment consists of mobile hosts fixed hosts and certain access points. The fixed hosts are all connected to a backbone (i.e. the Internet). Mobile hosts usually don't contact them directly, but use physically closer located hosts as access points to the backbone for means of minimizing the distance which has to be bridged by a mobile connection line. In addition to the users carrying a portable computer with them, also mobile users traveling between fixed hosts are considered in our system.
Problems in Wireless industry
o Handheld mobile devices could access network based content but the technologies were incompatible
o Not much use of existing internet infrastructure.
o No single global standard for data access for all handheld mobile devices.
METHODOLOGY
WAP
Wireless application protocol (WAP) is an application environment and set of communication protocols for wireless devices designed to enable to manufacturer vendor, and technology-independent access to the Internet and advanced telephony services .
WAP is designed for
􀂾 Primarily included mobile phones, pagers, PDA’s.
􀂾 Low bandwidth &high latency environments.
􀂾 Unpredictable stability & availability.
􀂾 Limited processing power & battery life.
􀂾 Less memory (ROM & RAM).
􀂾 Smaller displays.
WAP Applications
“At first, the most popular mobile Internet service is likely to be e-mail. SMS (short message service) messages have proved a big success in the Nordic nations and volumes are growing rapidly throughout western Europe”
One of the most significant advantages of Internet access from mobile rather that your PC is the ability to instantly identify users geographic location. This opens up a huge opportunity for highly customized services.
As Ericsson puts it, “the content providers will know where their users are geographically and will be able to direct them to specific destinations - restaurants or theaters, for example handheld devices are mobile, but their position is instantly identifiable. So think of content that knows where the user is, and offers content tailored to that geography. Weather forecasts, restaurant locations (with table availability and instant reservations fast food delivery, finding and booking a plumber, dating services (with pre-recorded video profiles and e-mail or voicemail exchanges) any service where physical proximity is important can migrate a vital part of its value-added to the new devices.”
The Problem areas One of the problem, basically to do with infrastructure (and not WAP) is that as the
mobile Internet access, thanks to WAP, increases it is likely to put ever greater demands on existing technology infrastructures as it encourages higher m-commerce volumes. A live example is I-mode services in Japan, where the mobile data access has seen a unprecedented rate of growth. So, unless the infrastructure is geared up to expect unexpected volumes, this can have significant impact on these data services since most of these systems are simply inadequate for big volumes. So there is a possibility of unsatisfactory performances observed by mobile data users.
Another problem area is that the delay in the delivery of long-promised terminals and service launches are narrowing the window of opportunity for WAP, while the proposed developments in faster mobile networks and more sophisticated terminals come closer. Further developments in WAP are still required and in the meantime, other solutions will emerge.
Also as with many other technologies what matters most and what guides the development of a technology is the emergence of “killer applications”. So, unless some killer applications hit the market, which influence the mood of the enduser, WAP just like other technologies has a difficult path ahead. Already due to lots of hype WAP proponents find them selves in a little tight position. So, this presents a big opportunity for the developer community to develop new and innovative applications that can realize the advantage of WAP. There is going to be big appetite for WAP applications in the very near future.
IMPLEMENTATION
J2ME
The Java 2 Platform, Micro Edition (J2ME) is the Java 2 platform targeted at consumer electronics and embedded devices like wireless phones, pagers, personal digital assistants, camcorders, game devices, small retail payment terminals and smart cards.
J2ME delivers the power and benefits of Java technology to consumer and embedded devices. It includes flexible user interfaces, a robust security model, a broad range of built-in network protocols, and extensive support for networked and offline applications that can be downloaded dynamically. Applications based on J2ME specifications are written once for a wide range of devices, yet exploit each device's native capabilities.
J2ME platform technology has three components which, taken together, form a compliant Java application environment:
􀂃 A Configuration is a combination of a Java virtual machine and a set of application support APIs that are shared across a class of devices.
􀂃 A Profile is a set of APIs (designed for a specific configuration) that address the needs of a narrower device category.
􀂃 An Optional Package is a set of technology-specific APIs that extends the capabilities of a Java application environment.
A J2ME-compliant Java application environment requires both a configuration and a profile. Optional Packages provide device designers and other JCP participants with a standards-based extension framework.
DIFFERENT TYPES OF CONFIGURATIONS
CLDC:
The CLDC configuration was designed to bring the many advantages of the Java platform to connected devices that are limited in available resources. Targeted devices include cellular phones, pagers, mobile point-of-sale terminals, and any other device constrained in processing power, memory, and graphical capability.
CDC:
The Connected Device Configuration is a standards-based framework for building and delivering mobile applications that can be shared across a range of network-connected personal mobile devices. Typically, these devices include a 32-bit microprocessor/controller and require about 2 MB of RAM and 2.5 MB of ROM for the Java application environment.
DIFFERENT TYPES OF PROFILES
Foundation Profile:
Foundation Profile is a set of Java APIs that support resource-constrained devices without a standards-based GUI system. Combined with the Connected Device Configuration
(CDC), Foundation Profile provides a complete J2ME application environment for consumer products and embedded devices.
Personal Basis Profile:
J2ME Personal Basis Profile is a set of Java APIs that support resource-constrained devices with a standards-based GUI framework. Combined with the Connected Device Configuration (CDC), J2ME Personal Basis Profile provides a complete J2ME application environment for consumer products and embedded devices.
Personal Profile:
J2ME Personal Profile is a set of Java APIs that supports resource-constrained devices with a GUI toolkit based on AWT. Combined with the Connected Device Configuration (CDC), J2ME Personal Profile provides a complete J2ME application environment for consumer products and embedded devices.

INFOSYS NEW 2010 QUESTION PAPER



1. There is a merry-go-round race going on.One person says,"1/3 of those in front of me and 3/4
of those behind me, give the total number of children in the race". Then the number of children
took part in the race? (repeated from previous papers)
Ans : 13

[ Assume there are x participants in the race.In a round race,no: of participants in front of a person wil be
x-1 an that behind him wil b x-1. i.e, 1/3(x-1) + 3/4(x-1) = x ; solving x = 13 ]

2. In an Island the natives lie and visitors speak truth. A man wants to know whether a salesman beside
him in a bar is a native or visitor. He asked him to ask a woman beside him whether she is a native or
visitor. He replied "she says she is a visitor". Then he knew that the salesman is a native or visitor.
salesman is in which category , native or visitor?

Ans : Native

[ Draw table and see ]

3.A man fixed an appointment to meet the manager, Manager asked him to come two days after the day before
the day after tomorrow. Today is Friday. When will the manager expect him? (repeated from previous papers)

Ans: Monday

[Don't confuse it with Tuesday.the correct answer is Monday]



5.A man said he spent 1/6 of his as a child, 1/12 as salesman in a liquor shop, 1/7 and 5 years as a politician
and a good husband respectively. At that time Jim was born. Jim was elected as Alderman four years back.when he
was half of his age. What is his age? (repeated from previous papers)

Ans: 84 years

[Assume that he lived x years.
X/6 + x/12 + x/7 + 5 + 4 + x/2 = x. Solving x= 84, Same as Question in Shakundala Devi book]

6.Jack,Doug and Ann, 3 children had a running race while returning from school.Mom asked who won the race.
Then Jack replied" I wont tell u.I wil give u a clue,When Ann takes 28 steps Doug takes 24 steps, meantime
I take 21 steps. Jack explained that his 6 steps equals Droug's 7 steps and Ann's 8 steps. Who won the race? (repeated from previous papers)

Ans: Doug

[ Ann steps = 8,16,24,28 --- finished by 3 & half full steps
Doug steps=7,14,21,24 --- finished before 3 & half full steps
Jack steps= 6,12,18,21 --- finished by 3 & half full steps
So Doug won the race ]

7. Every day a cyclist meets a car at the station.The road is straight and both are travelling in the same direction.
The cyclist travels with a speed of 12 mph.One day the cyclist comes late by 20 min. and meets the car 5miles before
the Station. What is the speed of the car?

Ans: 60 mph

[Very similar to Shakuntala Devi puzzles to puzzle you problem no: 38 ]


9.A lady goes for shopping. She bought some shoestrings. 4 times the number of shoestrings, she bought pins and 8 times,
handkerchiefs. She paid each item with their count as each piece's cost. She totally spent Rs. 3.24.How many handkerchiefs
did she buy? (repeated from previous papers)

10. Complete the series :

a) 3,6,13,26,33,66,____(repeated from previous papers)
b) 364,361,19,16,4,1,___( " " " )

Ans : a) 63
b) 1



11. Lucia is a wonderful grandmother. Her age is between 50 and 70.Each of her sons have
as many sons as they have brothers. Their combined number gives Lucia�s age. What is the age?

Ans: 64

12.There are two towers A and B. Their heights are 200ft and 150ft respectively and the
foot of the towers are 250ft apart. Two birds on top of each tower fly down with the same
speed and meet at the same instant on the ground to pick a grain. What is the distance
between the foot of tower A and the grain?

Ans:90ft

13 Grass in lawn grows equally thick and in a uniform rate.
It takes 40 days for 40 cows and 60 days for 30 cows to eat the whole of the grass.
How many days does it take for 20 cows to do the same?

Ans: 120

13. Four tourists A,B,C,D and four languages English, German, French and Italian.
They are not able to converse among themselves in one language.
Though A does not know English he can act as an interpreter between B and C.
No one spoke both French and German. A knows German and was able to converse with D
who doesn�t know a word in German. Only one language was spoken by more than two persons.
Each spoke two languages. Find who spoke what.

Ans : A- German,Italian
B- French,Italian
c- German,English
D- Italian,English



14. There is a five digit number. It has two prime digits (1 is not a prime number).
Third digit is the highest. Second digit is the lowest. First digit is one less
than the third digit. The fifth digit is half of the fourth. The sum of 4th and 5th is
less than the first. Find the number.

Ans � 71842

15.6. Four persons A, B, C and D are playing cards. Each person has one card, laid down
on the table below him, which has two different colours on either side.
No card has the same color on both sides. The colours visible on the table are Red,
Green, Red and Blue respectively. They see the color on the reverse side and give the
following comment.

A: Yellow or Green
B: Neither Blue nor Green
C: Blue or Yellow
D: Blue or Yellow

Given that out of the 4 people 2 always lie find out the colours on the cards each person.

Ans: A- Yellow
B- Yellow
C- Green
D- Red

16. A 1 k.m. long wire is held by n poles. If one pole is removed, the length of the gap
becomes 12/3m. What is the number of poles initially?


Ans:6km

17. Find the digits X,Y,Z
X X X X
Y Y Y Y +
Z Z Z Z
--------------
Y X X X Z
----------------
Ans: X Y Z
9 1 8

18. A man starts walking at 3 pm . ha walks at a speed of 4 km/hr on level ground and at a speed of
3 km/hr on uphill , 6 km/hr downhill and then 4 km/hr on level ground to reach home at 9 pm.
What is the distance covered on one way?

Ans: 12 km

19. A grandma has many sons; each son has as many sons as his brothers. What is her age if it�s the product
of the no: of her sons and grandsons plus no: of her sons?(age b/w 70 and 100).

Ans: 81

20. An electric wire runs for 1 km b/w some no: of poles. If one pole is removed the distance b/w each pole
increases by 1 2/6 (mixed fraction). How many poles were there initially?

21. There is a church tower 150 feet tall and another catholic tower at a distance of 350 feet from it which
is 200 feet tall. There is one each bird sitting on top of both the towers. They fly at a constant speed
and time to reach a grain in b/w the towers at the same time. At what distance from the church is the grain?

Ans: 90

22. A person wants to meet a lawyer and as that lawyer is busy he asks him to come three days after the before day
of the day after tomorrow? on which day the lawyer asks the person to come?

ans: thursday

23. A person is 80 years old in 490 and only 70 years old in 500 in which year is he born?

ans: 470

24.A person says that their speed while going to a city was 10mph however while returning as there is no much
traffic they came with a speed of 15mph. what is their average speed?

ans: 12mph

25. There is a peculiar island where a man always tells truth and a women never says two 2 consecutive truth
or false statements that is if she says truth statement then she says false statement next and vice versa.
A boy and girl also goes in the same way. one day i asked a child " what r u a boy or a girl" however the
child replied in their language that i dint understand but the parents knew my language and one parent replied
that " kibi is a boy" the other one said that "no kibi is a girl, kibi lied".
a: is kibi a boy or a girl
b: who ansered first mother or father?

ans: kibi is a girl and mother answered first.

26. The boy goes to school reaches railway station at his 1/3 of his journey& mill at 1/4 of his journey the time
taken him to walk between railway station & mill is 5 mins. Also he reaches railway station at 7.35amwhen he
started from house& when he reaches school?

Ans: 7:15to8.15

27. if a person is sitting in a exam having 30 questions (objective type)
the examiner use the formula to calculate the score is S=30+4c-w here c is number
of correct answer and w is number of wrong answer , the examiner find the score
is more than 80, tell how may questions are correct ? if the score is little less
but still more than 80 then u wont be able to answer.

ans :- 16


28. if a person having 1000 rs and he want to distribute this to his five children
in the manner that ecah son having 20 rs more than the younger one , what will
be the share of youngest child

ans- 160

29.raju having some coins want to distribute to his 5 son , 5 daughter and driver
in a manner that , he gave fist coin to driver and 1/5 of remaining to first
son he again gave one to driver and 1/5 to 2nd son and so on....
at last he equally distributed all the coins to 5 daughters.
how many coins raju initially have???

ans:-881

30.if ravi binded his book and the binder cut the pages of the book , ravi
decided to mark the pages by himself own , what he found that number of three
appears 61 times find of number of pages answer

ans - 300

31. a painter went in a exhibition to purchases some pictures where T,U,V,W,X,Y,Z
pictures were remaining , he want to buy only five in the condition on that
if T is there then X should not be there,
if U is there than y should be there
if if v is there then X should be there

which is the combination the painter can have
(a) T,U,V,W,Y
(b)T,Z,U,W,X
(c)T,X,U,V,W
(d)T,U,Y,W,Z

ans (d)

32.There are 100 men in town. Out of which 85% were married, 70% have a phone, 75% own a car, 80% own
a house. What is the maximum number of people who are married, own a phone, own a car and own a house ? ( 3 marks)

Sol: 15%

33. There are 10 Red, 10 Blue, 10 Green, 10 Yellow, 10 White balls in a bag. If you are blindfolded
and asked to pick up the balls from the bag, what is the minimum number of balls required to get a
pair of atleast one colour ? ( 2 Marks)

Sol :6 balls.

34. Triplet who usually wear same kind and size of shoes, namely, Annie, Danny, Fanny. Once one of them
broke a glass in kitchen and their shoe prints were there on floor of kitchen. When their mother asked
who broke Annie said, �I didn�t do it�; Fanny said �Danny did it�; Danny said �Fanny is lieing�;
here two of them are lieing, one is speaking truth. Can you find out who broke it ? (3 Marks)

Sol : Annie

35. 4 players were playing a card game. Cards had different colours on both sides. Neither of cards had
same colour on both sides. Colours were 2 Red, 2 Blue, 2 Green, 2 Yellow. Cards were lying in front of
each player. Now, each player knew the colour on other side of his card. They are required to tell their colour.
Statement given by each of them was :
Annie : Blue or Green
Bobby : Neither Blue nor Green
Cindy : Blue or Yellow
Danny : Blue or Yellow
colours of cards that are visible to all were Red, Blue, Green, Blue in order of their names.
Exactly two of them are telling truth and exactly two of them are lieing. Can you tell the colour
on other face of card for each player ? (6 Marks)

Sol : Annie : Yellow (Lieing)
Bobby : Yellow (Telling truth)
Cindy : Blue (Telling truth)
Danny : Green (Lieing)

36. In a game i won 12 games, each game if i loose i will give u one chocolate, You have 8 chocolates how
many games played.

Ans : 32

38. 75 persons Major in physics, 83 major in chemistry, 10 not at major in these subjects
u want to find number of students majoring in both subjects

Ans 68.

39. if A wins in a race against B by 10 mts in a 100 Meter race. If B is behind of A by 10 mts.
Then they start running race, who will won?

Ans A

40. A+B+C+D=D+E+F+G=G+H+I=17
given A=4.Find value of G and H?

Ans : G = 5 E=1

41. One guy has Rs. 100/- in hand. He has to buy 100 balls. One football costs Rs. 15/, One Cricket ball
costs Re. 1/- and one table tennis ball costs Rs. 0.25 He spend the whole Rs. 100/- to buy the balls.
How many of each balls he bought?

ans :F=3,T=56,C=41


42. The distance between Station Atena and Station Barcena is 90 miles. A train starts from Atena towards
Barcena. A bird starts at the same time from Barcena straight towards the moving train. On reaching the
train, it instantaneously turns back and returns to Barcena. The bird makes these journeys from Barcena to
the train and back to Barcena continuously till the train reaches Barcena. The bird finally returns to Barcena and rests. Calculate the total distance in miles the bird travels in the following two cases:
(a) The bird flies at 90 miles per hour and the speed of the train is 60 miles per hour.
(b) the bird flies at 60 miles per hour and the speed of the train is 90 miles per hour

Ans: time of train=1hr.so dist of bird=60*1=60miles


43. A tennis championship is played on a knock-out basis, i.e., a player is out of the tournament when
he loses a match.
(a) How many players participate in the tournament if 15 matches are totally played?
(b) How many matches are played in the tournament if 50 players totally participate?

Ans: (a)16
(b)49

44.When I add 4 times my age 4 years from now to 5 times my age 5 years from now, I get 10 times my
current age. How old will I be 3 years from now?

Ans:Age=41 years.

45.A rich merchant had collected many gold coins. He did not want anybody to know about them.
One day, his wife asked, "How many gold coins do we have?" After pausing a moment, he replied,
"Well! If I divide the coins into two unequal numbers, then 37 times the difference between the
two numbers equals the difference between the squares of the two numbers." The wife looked puzzled.
Can you help the merchant's wife by finding out how many gold R

Ans:37

46. A set of football matches is to be organized in a "round-robin" fashion, i.e., every participating
team plays a match against every other team once and only once. If 21 matches are totally played,
how many teams participated?

Ans :7

47. Glenn and Jason each have a collection of cricket balls. Glenn said that if Jason would give him
2 of his balls they would have an equal number; but, if Glenn would give Jason 2 of his balls,
Jason would have 2 times as many balls as Glenn. How many balls does Jason have?

Ans: 14

48. Suppose 8 monkeys take 8 minutes to eat 8 bananas.
a) How many minutes would it take 3 monkeys to eat 3 bananas?
(b) How many monkeys would it take to eat 48 bananas in 48 minutes

Ans: a)48
B)6

49. It was vacation time, and so I decided to visit my cousin's home. What a grand time we had!
In the mornings, we both would go for a jog. The evenings were spent on the tennis court. Tiring
as these activities were, we could manage only one per day, i.e., either we went for a jog or played
tennis each day. There were days when we felt lazy and stayed home all day long. Now, there were 12
mornings when we did nothing, 18 evenings when we stayed at home, and a total of 14 days when we jogged
or played tennis. For how many days did I stay at my cousin's place?

Ans : 22 days

50 A 31" x 31" square metal plate needs to be fixed by a carpenter on to a wooden board. The carpenter
uses nails all along the edges of the square such that there are 32 nails on each side of the square.
Each nail is at the same distance from the neighboring nails. How many nails does the carpenter use?

Ans :124

Top

51. A man starts his walking at 3PM from point A, he walks at the rate of 4km/hr in plains and 3km/hr in hills to reach the point B.
During his return journey he walks at the rate of 6km/hr in hills and 4km/hr in plains and reaches the point A at 9PM.
What is the distance between A and B?

Ans: 12km

52.2. A boy asks his father, " what is the age of grand father?". Father replied " He is x years old in x^2 years", and also said, "we are talking
about 20th century". what is the year of birth of grand father?

Ans: 1892

53. A boy travels in a scooter after covering 2/3rd of the distance the wheel got punctured he covered the remaining distance by walk.
Walking time is twice that of the time the boy�s riding time. How many times the riding speed as that of the walking speed?

Ans: 4 times.

54. In a Knockout tournament 51 teams are participated, every team thrown out of the tournament if they lost twice. How many matches to
be held to choose the winner?

Ans: 101 matches

55. A man sold 2 pens. Initial cost of each pen was Rs. 12. If he sell it together one at 25% profit and another 20% loss. Find the amount of loss
or gain, if he sells them seperately.

Ans: 60 Paise gain

56. Find the 3 digit no. whose last digit is the squareroot of the first digit and second digit is the sum of the other two digits.

Ans: 462

57. Meera was playing with her brother using 55 blocks.She gets bored playing and starts arranging the blocks such that the no. of blocks in each row is
one less than that in the lower row. Find how many were there in the bottom most row?

Ans: 10

58. Two people are playing with a pair of dies. Instead of numbers, the dies have different colors on theirsides. The first person wins if the same color
appears on both the dies and the second person wins if the colors are different. The odds of their winning are equal. If the first dice has 5 red sides
and 1 blue side, find the color(s) on the second one.

Ans: 3 Red, 3 Blue

59. A person travels in a car with uniform speed. He observes the milestone,which has 2 digits. After one hour he observes another milestone
with same digits reversed. After another hour he observes another milestone with same 2 digits separated by 0. Find the speed of the car?

Ans : 45

60. Three persons A, B &C went for a robbery in different directions and they theft one horse, one mule and one camel.
They were caught by the police and when interrogated gave the following statements
A: B has stolen the horse

B: I didn't rob anything.

C: both A & B are false and B has stolen the mule.

The person who has stolen the horse always tell the truth and

The person who has stolen the camel always tell the lie.

Find who has stolen which animal?

Ans:

A- camel

B- mule

C- horse

61. One quarter of the time till now from midnight and half of the time

remaining from now up to midnight adds to the present time. What is the present time?

Ans: 9:36AM

62. After world war II three departments did as follows First department gave some tanks to 2nd &3rd departments equal to the
number they are having. Then 2nd department gave some tanks to 1st & 3rd departments equal to the number they are having.
Then 3rd department gave some tanks to 2nd &1st departments equal to the number they are having. Then each department has 24 tanks.
Find the initial number of tanks of each department?

Ans ;

A-39

B-21

C-12

63. A, B, C, D&E are having their birthdays on consecutive days of the week not ecessarily in the same order. A 's birthday comes before G's
as many days as B's birthday comes after E's. D is older than E by 2 days. This time G's birthday came on wednesday. Then find the day
of each of their birthdays?

Ans:

Birthday of D on SUNDAY

Birthday of B on MONDAY

Birthday of E on TUESDAY

Birthday of G on WEDNESDAY

Birthday of A on THURSDAY

64. A girl 'A' told to her friend about the size and color of a snake she has seen

in the beach. It is one of the colors brown/black/green and one of the sizes 35/45/55.

If it were not green or if it were not of length 35 it is 55.

If it were not black or if it were not of length 45 it is 55.

If it were not black or if it were not of length 35 it is 55.

a) What is the color of the snake?

b) What is the length of the snake?

Ans:

a) brown

b) 55

65. There are 2 pesons each having same amount of marbles in the

beginning. after that 1 person gain 20 more from second person n he

eventually lose two third of it during the play n the second person

now have 4 times marble of what 1st person is having now.

find out how much marble did each had in the beginning.

ANSWER - 100 each

66. A lady was out for shopping. she spent half of her money in buying A

and gave 1 doller to bagger. futher she spent half of her remaining

money and gave 2 doller to charity. futher she spent half of

remaining money n gave 3 dollor to some childrans. now she has left

with 1 doller. how much she had in the beginning?

Ans $42

67. There are certain diamonds in a shop.

1 thief stole half of diamonds and 2 more.

2 thief stole half of remaining and 2 more

3. same as above

4 same as above.

5 came nothing was left for that.

how many dimands was there???

Ans 60 diamonds

68. There are three frens A B C.

1. Either A or B is oldest

2. Either C is oldest or A is youngest.

Who is Youngest and who is Oldest?

Ans A is youngest n B is oldest.

69. Father says my son is five times older than my daughter. my wife is 5

times older that my son. I am twice old from my wife and altogether

(sum of our ages) is equal to my mother 's age and she is celebrating

her 81 birthday. so what is my son's age?

Ans - 5 years.

70.. In Mulund, the shoe store is closed every Monday, the boutique is closed every Tuesday, the grocery store is closed every Thursday
and the bank is open only on Monday, Wednesday and Friday. Everything is closed on Sunday.

One day A, B, C and D went shopping together, each with a different place to go. They made the following statements:

A D and I wanted to go earlier in the week but there wasn�t day when we could both take care of our errands.
B I did not want to come today but tomorrow I will not be able to do what I want to do.
C I could have gone yesterday or the day before just as well as today.
D Either yesterday or tomorrow would have suited me.

Which place did each person visit ?

Ans : A-BOUTIQUE

B-BANK

C-GROCERY

D-SHOE

71. Fodder, pepsi and cereale often eat dinner out.

each orders either coffee or tea after dinner.
if fodder orders coffee, then pepsi orders the drink that cereale orders
if pepsi orders coffee, then fodder orders the drink that cereale doesnot oder
if cereale orders tea, then fodder orders the drink that pepsi orders
which person/persons always orders the same drink after dinner ?

Ans:Fodder

72. At a recent birthday party there were four mothers and their children. Aged 1,2,3 and 4. from the clues below can you work out whose
child is whose and their relevant ages ?

It was jane�s child�s birthday party.
Brian is not the oldest child.
Sarah had Anne just over a year ago.
Laura�s Child will be next birthday.
Daniel is older than Charlie is.
Teresa�s child is the oldest.
Charlie is older than Laura�s child.
Ans: Jane � Charlie -3

Laura � Brian � 2

Teresa � Daniel � 4

Sarah � Anne - 1

73. We are given 100 pieces of a puzzle. If fixing two components together is counted as 1 move ( a component can be one piece or an already fixed set of pieces),
how many moves do we need to fix the entire puzzle.

Ans: 99

74. Two guys work at some speed...After some time one guy realises he has done only half of the other guy completed which is equal to half of
what is left !!! #$%#$ So how much faster than the other is this guy supposed to do to finish with the first.
Ans: one and half times or 3/2

75. There is a square cabbage patch.He told his sister that i have a larger patch than last year and hence
more cabbages thios year.Then how many cabbages i have this year.?

Ans:106*106=11236

76. There are three guesses on the color of a mule

1 says:itz not black

2 says:itz brown or grey

3 says: itz brown

Atlest one of them is wrong and one of them is

true.....Then whatz the color of mule?

Ans: Grey

77. Jim,Bud and sam were rounded up by the police yesterday. because one

of them was

suspected of having robbed the local bank. The three suspects made

the following statements

under intensive questioning.

Jim: I'm innocent

Bud: I'm innocent

Sam: Bud is the guilty one.

If only one of the statements turned out to be true, who robbed the

bank?

Ans:BUD.

78. There are two containers on a table. A and B . A is half full of

wine, while B, which is twice A's size,

is onequarter full of wine . Both containers are filled with water

and the contents are poured into a

third container C. What portion of container C's mixture is wine ?

Ans:33.33%

79. A man was on his way to a marriage in a car with a constant speed.

After 2 hours one of the tier is punctured and it took 10 minutes to replace it.

After that they traveled with a speed of 30 miles/hr and reached the marriage

30 minutes late to the scheduled time. The driver told that they would be

late by 15 minutes only if the 10 minutes was not waste.

Find the distance between the two towns?

Ans: 120 miles

80. A bargainhunter bought some plates for $ 1.30 from a sale on saturday,where price 2cents was marked off at each article .On monday she went to return them at regular prices,and bought some cups and saucers from that much amount of money only.the normal price of plate were equal to the price of 'one cup and one saucer'.

In total she bought 16 items more than previous. saucers were only of 3 cents hence she brought 10 saucers more than the cups,

How many cups and saucers she bought and at what price?

Ans: 8,18 Price: 12,3.

81. Mr. T has a wrong weighing pan.One arm is lengthier than other.1

kilogram on left balances 8 melons on right.1 kilogram on right

balances 2 melons on left.If all melons are equal in weight,what is

the weight of a single melon?

Ans:200 gms

82. A card boarb of 34 * 14 has to be attached to a wooden box and a total

of 35 pins are to be used on the each side of the cardbox.Find the total

number of pins used .

Ans: 210

Saturday, March 06, 2010

best practices in coding

Some basic issues in every development team
fundamental discipline issues in coding
number of years of exp. does not match delivery
by the time they actually become good coders, they are promoted to leads
70% of the whole employees, belong 0-4 years of experience

In India, senior developer means 3-5 years of exp, in USA, senior developer means 6-10 years of exp – There is a huge gap in expectation and quality

Coding is not rocket science

The rework time in coding is the actual killer
20-25% of the time is spent in reworking in software – that means, fix the mistakes done
In a mobile phone, can you insert sim card wrongly? You cannot. Because the sim card design is like that. So the highest level maturity is not to give an opportunity to make mistakes

As a kid, you were asked and helped to brush the teeth. It was tough to brush teeth.
One fine morning, you start brushing teeth by yourselves.
Then it has become a habit. You need not be told to do brushing by anyone.
Commenting is necessary for maintaining any program
Without commenting, the program is not complete
Do not assume that the other person who reads this program will understand it clearly
If commenting is not done at the beginning, it is forgotten.

Program - a physical file – you need to comment the following at the top.
at the top of the program - header comment
what the program achieves
who coded on what day

Classes
Comment at the beginning of the class about what the class does
class Employee
// this class is used to manage all information
// about employees and retrieve specific data

Methods within classes
what this method/function/procedure does
what are the parameters and their purpose
what are the return values

Comment before every loop.

Comment before every file or database operation

Comment before every if condition
If you are team leader, if your team member comes with a code, that does not have these comments – what will you do?
You take over a program for maintenance from another person, and that program has no comments – what will you do?
Your company hands over a project to client. Programs do not have comments. What the client will say?
Readability improves understanding; that further improves maintainability
If programs are not consistent, maintenance is tough
If 20 developers work in a project and each one names functions in the way he/she wants, will the client approve the same?
We must have a document on naming conventions
Every document must be named properly and it must be stored in a proper folder.
You need to have a convention for naming
Programs
Classes
Methods
Variables
Labels in programs
Reusable library functions
There are established methods like Pascal casing, camel casing etc.
Usually you will tend to use a mixture of uppercase, lowercase letters, underscore etc
The ultimate aim is to achieve consistency across programs
Placing a number or quoted text inside active code is hard coding
This is deadly as the program restricts itself to this hard coded value
To make a change, you need to change code, recompile and redeploy
Usual way to avoid hard coding is to use constants at the top of a program; here also, you need to edit the program, but the change is in one place
Other way is to put all configurable values in a csv or ini or dat file. Every program must read the name value pair from the file and later use them in the code
Eg. MAX_LENGTH 150, PORT 8097

Modularity is important for easy maintenance
Do not write lengthy methods or procedures
We can split the modules based on
A functional operation as per requirements
A piece of code is used in more than one place
Logical breakdown of events in the functionality
Modularity must be decided right at the design level itself
Modular programs are easy to debug
Fixes done on modular programs are easy to isolate from other regression effects
A loop is - repeat some logic for specific number of times or as long as a condition is true/false
If this is not checked, it can run forever, infinitely and can bring down the server
Loop Sample
gateway 1 // variables, flags
xyz = 10
loop starts here
...gateway 2 // variables, flags, counters
..
logic
... gateway 3
loop ends here
gateway 4
Gateways are the check posts where we must watch the value of the variables, loop counters and loop flags
Ensure proper resetting of flags and counters and check their values and gateways of the loops
Never allocate memory inside a loop
Never instantiate a class inside a loop; if needed, close it within the loop
Usually companies do not suggest more than 3 levels in the loops

Issues may be caused by programmer
Issues may be caused by system
Most of the languages allow try-catch or on-error-goto exceptions

Exception is also an error condition
we do not know when it will happen

1. Any file operations – handle exceptions, because
file may not exist
file is already opened by someone
file does not have privilege
file is already full

2. Any database operation – handle exceptions, because
database you may not have rights
database is down
connections exhausted

3. Memory
low memory exception
pointers - writing in privileged memory
array boundary breach

4. Any external evices
your program accesses webcam or printer
We need to monitor cpu, memory, network

Memory is directly related to variables and object – do not declare huge arrays or objects

Cpu is consumed more when you deal with db or files or devices

Any database operations, open late and close the connection early.

Usage of indexes in queries must be examined

Any column used in where condition of db query must have index on it

Any memory allocated must be freed – else the program will shut down after some time

Any object instantiated must be released – else system will be depleted of memory and hence performance will come down
Usually the logic design will be provided to the developer
If it is not provided, take 30 minutes and write the logic of the program in English first
Do not start coding right away. You will make so many assumptions and it will spoil the show
Get the logic approved by the team lead and then start coding
Developers usually feel that this takes time; but it reduces the time effectively while coding and reworking
Since developers are not used to documenting, they feel it is not their job. Hence they miss a lot of finer points
If you write the logic first, you will get a lot of clarifications at that time itself and hence the code will come out clean

Sample Test Paper For CHSSC

1.In case of Unix File System , how many pointers from I Node block are needed to
access memory size of 1,00,000 bytes of data?(Let one pointer = 4 bytes, 1 block =
512 bytes)
a)11
b)12
c)13
d)10
2.Withdrawing cash from a bank is an example of …………….processing.
a) independent
b) cooperative
c) both a) and b)
d) none of these
3.Consider the following instruction:
move r0,#3324
move [r0],#5
The data 5 can be found at …………………. after the execution of this instruction.
a) location whose address is 3324
b)at r0
c)location whose address is 5
d)none of thes
4.With the help of single indirect pointer,total data that could be reffered to is:
a) 128bytes
b) 512bytes
c) 70656bytes
d) 32bytes
5. Lexical Analysis performs
a) CHECKS THE CORRECT USAGE OF KEYWORDS,CONSTANTS,IDENTIFIERS
AND TOKENS.
b) STORES THE INFORMATION ABOUT
KEYWORDS,CONSTANTS,IDENTIFIERS IN SYMBOL TABLE.
C) STORES THE INFORMATION ABOUT
KEYWORDS,CONSTANTS,IDENTIFIERS IN PARSE TREES.
d) CHECKS THE VALIDITY OF ASSIGNMENT OPERATIONS.
6. In fully connected network for 3 and 4 sites number of hops is
a) 1
b) 2
c) 0
d) 3
7. Examine the following code segment
for(i=0,i{
a=a+i;
}
The error given during compilation is the responsibiity of
a) Lexical Analyser
b) Semantic analyser
c) Syntactic Analyser
d) Code optimization
8. When the page size decreases, the number of page fault increases.
a) true
b) false
c) cannot be stated
d) no choice
9. Where we need the idea of compaction in the memory management
a) variable partition allocation
b) fixed partition allocation
c) re-locatable partition allocation
d) single contiguous allocation
10. Which type of scheme does windows3.1 have
a) preemptive multitasking
b) preemptive scheduling
c) uni programming
d) co-operative multitasking

C language programs

1. main()
{
int i=-1,j=-1,k=0,l=2,m;
m=i++&&j++&&k++||l++;
printf("%d %d %d %d %d",i,j,k,l,m);
}
Answer:
0 0 1 3 1
2. main()
{
int i=3;
switch(i)
{
default:printf("zero");
case 1: printf("one");
break;
case 2:printf("two");
break;
case 3: printf("three");
break;
}
}
Answer :
three
3. main()
{
printf("%x",-1<<4 br="">}
Answer:
fff0
4. main()
{
int c=- -2;
printf("c=%d",c);
}
Answer:
c=2;
5. main()
{
int i=10;
i=!i>14;
Printf ("i=%d",i);
}
Answer: i=0
1
6. main()
{
printf("\nab");
printf("\bsi");
printf("\rha");
}
Answer:
hai
7. main()
{
int i=5;
printf("%d%d%d%d%d%d",i++,i--,++i,--i,i);
}
Answer:
45545
8. main()
{
printf("%p",main);
}
Answer:
Some address will be printed
9. main()
{
int i=400,j=300;
printf("%d..%d");
}
Answer:
400..300
10. void main()
{
int i=5;
printf("%d",i++ + ++i);
}
Answer:
Output Cannot be predicted exactly.
11. void main()
{
int i=5;
printf("%d",i+++++i);
}
Answer:
Compiler Error
2
12. #include
main()
{
int i=1,j=2;
switch(i)
{
case 1: printf("GOOD");
break;
case j: printf("BAD");
break;
}
}
Answer:
Compiler Error: Constant expression required in function main.
13. main()
{
int i;
printf("%d",scanf("%d",&i)); // value 10 is given as input here
}
Answer:
1
14. main()
{
int i=0;
for(;i++;printf("%d",i)) ;
printf("%d",i);
}
Answer:
1
15. main()
{
printf("%d", out);
}
int out=100;
Answer:
Compiler error: undefined symbol out in function main.
16. main()
{
int i=-1;
+i;
printf("i = %d, +i = %d \n",i,+i);
}
Answer:
i = -1, +i = -1
3
17. main()
{
char not;
not=!2;
printf("%d",not);
}
Answer:
0
18. main()
{
int k=1;
printf("%d==1 is ""%s",k,k==1?"TRUE":"FALSE");
}
Answer:
1==1 is TRUE
19. main()
{
int y;
scanf("%d",&y); // input given is 2000
if( (y%4==0 && y%100 != 0) || y%100 == 0 )
printf("%d is a leap year");
else
printf("%d is not a leap year");
}
Answer:
2000 is a leap year
20. main()
{
int i=-1;
-i;
printf("i = %d, -i = %d \n",i,-i);
}
Answer:
i = -1, -i = 1
21. #include
main()
{
const int i=4;
float j;
j = ++i;
printf("%d %f", i,++j);
}
Answer:
Compiler error
4
22. main()
{
int i=5,j=6,z;
printf("%d",i+++j);
}
Answer:
11
23. main()
{
int i =0;j=0;
if(i && j++)
printf("%d..%d",i++,j);
printf("%d..%d,i,j);
}
Answer:
0..0
24. int i;
main(){
int t;
for ( t=4;scanf("%d",&i)-t;printf("%d\n",i))
printf("%d--",t--);
}
// If the inputs are 0,1,2,3 find the o/p
Answer:
4--0
3--1
2--2
25. main(){
int a= 0;int b = 20;char x =1;char y =10;
if(a,b,x,y)
printf("hello");
}
Answer:
hello
26. void main()
{
unsigned giveit=-1;
int gotit;
printf("%u ",++giveit);
printf("%u \n",gotit=--giveit);
}
Answer:
0 65535
5
27. main()
{
float me = 1.1;
double you = 1.1;
if(me==you)
printf("I love U");
else
printf("I hate U");
}
Answer:
I hate U
28.a<<1 2="" a="" above="" adding="" b="" br="" by="" c="" d="" dividing="" equivalent="" is="" multiplying="" none="" of="" the="" to="">29. The operation of a stair case switch best explains the a) or operation b) and operation c)exclusive nor operation d)exclusive or operation
30. Which of the following is/are syntactically correct? a) for(); b) for(;); c) for(,); d) for(;;);
31. The expression 4+6/3*2-2+7%3 evaluates to a) 3 b) 4 c) 6 d) 7
32.Any C program a) must contain at least one function b) need not contain ant function c) needs input data d) none of the above
33. Using goto inside for loop is equivalent to using a) continue b) break c) return d)none of the above
34.The program fragment inta=5,b=2; printf(“%d”,a+++++b); a) prints 7 b)prints 8 c) prints 9 d)none of the above
35. printf(“ab” , “cd”,”ef”); prints a) ab abcdef c) abcdef, followed by garbage value d) none of the above
36. Consider the following program segment. i=6720; j=4;
while((i%j)==0)
{
i=i/j;
j=j+1;
}
On termination j will have the value
a) 4 b) 8 c) 9 d) 6720
UNIT-II
Predict the output or error(s) for the following:
6
37. main()
{
char s[ ]="man";
int i;
for(i=0;s[ i ];i++)
printf("\n%c%c%c%c",s[ i ],*(s+i),*(i+s),i[s]);
}
Answer:
mmmm
aaaa
nnnn
38. main()
{
extern int i;
i=20;
printf("%d",i);
}
Answer:
Linker Error : Undefined symbol '_i'
39. #define int char
main()
{
int i=65;
printf("sizeof(i)=%d",sizeof(i));
}
Answer:
sizeof(i)=1
40. #define square(x) x*x
main()
{
int i;
i = 64/square(4);
printf("%d",i);
}
Answer:
64
41. #include
#define a 10
main()
{
#define a 50
printf("%d",a);
7
}
Answer:
50
42. #define clrscr() 100
main()
{
clrscr();
printf("%d\n",clrscr());
}
Answer:
100
43. main()
{
clrscr();
}
clrscr();
Answer:
No output/error
44. main()
{
int i=1;
while (i<=5)
{
printf("%d",i);
if (i>2)
goto here;
i++;
}
}
fun()
{
here:
printf("PP");
}
Answer:
Compiler error: Undefined label 'here' in function main
45. #define f(g,g2) g##g2
main()
{
int var12=100;
printf("%d",f(var,12));
}
Answer:
100
8
46. main()
{
extern out;
printf("%d", out);
}
int out=100;
Answer:
100
47. main()
{
show();
}
void show()
{
printf("I'm the greatest");
}
Answer:
Compier error: Type mismatch in redeclaration of show.
48. int i,j;
for(i=0;i<=10;i++)
{
j+=5;
assert(i<5 br="">}
Answer:
Runtime error: Abnormal program termination.
assert failed (i<5 file="" name="">,
49. #define FALSE -1
#define TRUE 1
#define NULL 0
main() {
if(NULL)
puts("NULL");
else if(FALSE)
puts("TRUE");
else
puts("FALSE");
}
Answer:
TRUE
50. #define max 5
#define int arr1[max]
main()
{
typedef char arr2[max];
arr1 list={0,1,2,3,4};
9
arr2 name="name";
printf("%d %s",list[0],name);
}
Answer:
Compiler error (in the line arr1 list = {0,1,2,3,4})
51. int i=10;
main()
{
extern int i;
{
int i=20;
{
const volatile unsigned i=30;
printf("%d",i);
}
printf("%d",i);
}
printf("%d",i);
}
Answer:
30,20,10
52. #include
main()
{
int a[2][2][2] = { {10,2,3,4}, {5,6,7,8} };
int *p,*q;
p=&a[2][2][2];
*q=***a;
printf("%d..%d",*p,*q);
}
Answer:
garbagevalue..1
53. #include
main()
{
register i=5;
char j[]= "hello";
printf("%s %d",j,i);
}
Answer:
hello 5
54. main()
{
int i=_l_abc(10);
10
printf("%d\n",--i);
}
int _l_abc(int i)
{
return(i++);
}
Answer:
9
55. main()
{
char c=' ',x,convert(z);
getc(c);
if((c>='a') && (c<='z'))
x=convert(c);
printf("%c",x);
}
convert(z)
{
return z-32;
}
Answer:
Compiler error
56. main()
{
int i;
i = abc();
printf("%d",i);
}
abc()
{
_AX = 1000;
}
Answer:
1000
57. What are the following notations of defining functions known as?
i. int abc(int a,float b)
{
/* some code */
}
ii. int abc(a,b)
int a; float b;
{
/* some code*/
}
Answer:
11
i. ANSI C notation
ii. Kernighan & Ritche notation
58. void main()
{
static int i=5;
if(--i){
main();
printf("%d ",i);
}
}
Answer:
0 0 0 0
59. void main()
{
int k=ret(sizeof(float));
printf("\n here value is %d",++k);
}
int ret(int ret)
{
ret += 2.5;
return(ret);
}
Answer:
Here value is 7
60. void main()
{
char a[]="12345\0";
int i=strlen(a);
printf("here in 3 %d\n",++i);
}
Answer:
here in 3 6
61. void main()
{
int i;
char a[]="\0";
if(printf("%s\n",a))
printf("Ok here \n");
else
printf("Forget it\n");
}
Answer:
Ok here
12
62. main()
{
clrscr();
}
clrscr();
Answer:
No output/error
63. main()
{
static int var = 5;
printf("%d ",var--);
if(var)
main();
}
Answer:
5 4 3 2 1
64.Cpreprocessor a) tales care of conditional compilation b) tales care of macros c) tales care of include files d) acts before compilations
65.A preprocessor command a) need not start on a new line b) need not start on the first column c) has # as the first character d) comes before the first executable statement
66. The following program
main()
{
int a=4;
change(a);
printf(“%d”,a);
}
change(int a)
{ printf(“%d”,++a); } outputs a)5 5 b)4 5 c) 5 4 d)4 4
67. The output of the following program is
main()
{
static int x[]={1, 2, 3, 4, 5, 6, 7, 8};
int i;
for(i=2;i<6 br="" i="">x[x[i]]=x[i];
for(i=0; i<8 br="" i="">printf(“%d”,x[i]);
}
a) 1 2 3 3 5 5 7 8 b)1 2 3 4 5 6 7 8 c) 8 7 6 5 4 3 2 1 d)1 2 3 5 4 6 7 8
13
68. The order in which actual parameters are evaluated in a function call a) is from the left b)is from the right c) is compiler dependent d)none of the above
69. The default parameter passing mechanism is a) call by value b) call by reference c) call by value result d) none
70. C does no automatic array bound checking. This is a) true b) false c) C’s asset d) C’s shortcoming
71. If a two dimensional array is used as a formal parameter, then a) both the subscripts may be left empty b) the first( row) subscript may be left empty
c)the first subscript must be left empty d) both the subscripts must be left empty
72. If storage class is missing in the array definition, by default it will be taken to be
a) automatic b) external c) static
d) either automatic or external depending on the place of occurrence
73. Consider the declaration static char hello[]=”hello”; The output of printf(“%s\n”,hello); will be the same as that of a) puts( “hello”); b) puts(hello); c) printf(“%s\n”,”hello”); d) puts(“hello\n”);
74. The array name can be pointer to a) another array b) another variable c) to that array only d) none
75. Array of pointers to table of strings saves a) time b) memory c) CPU utilization d)none of the above
76. The following program
main()
{
inc(); inc(); inc();
}
inc()
{
static int x;
printf(“%d”,++x);
} prints
a)0 1 2 b) 1 2 3 c) 3 consecutive, but unpredictable numbers d) 1 1 1
UNIT-III
Predict the output or error(s) for the following:
77. main()
{
int c[ ]={2.8,3.4,4,6.7,5};
int j,*p=c,*q=c;
for(j=0;j<5 br="" j="">printf(" %d ",*c);
14
++q; }
for(j=0;j<5 br="" j="">printf(" %d ",*p);
++p; }
}
Answer:
2 2 2 2 2 2 3 4 6 5
78. main()
{
char *p="hai friends",*p1;
p1=p;
while(*p!='\0') ++*p++;
printf("%s %s",p,p1);
}
Answer:
ibj!gsjfoet
79. void main()
{
char far *farther,*farthest;
printf("%d..%d",sizeof(farther),sizeof(farthest));
}
Answer:
4..2
80. main()
{
char *p;
p="Hello";
printf("%c\n",*&*p);
}
Answer:
H
81. main()
{
static char names[5][20]={"pascal","ada","cobol","fortran","perl"};
int i;
char *t;
t=names[3];
names[3]=names[4];
names[4]=t;
for (i=0;i<=4;i++)
printf("%s",names[i]);
}
15
Answer:
Compiler error: Lvalue required in function main
82. #include
main()
{
char s[]={'a','b','c','\n','c','\0'};
char *p,*str,*str1;
p=&s[3];
str=p;
str1=s;
printf("%d",++*p + ++*str1-32);
}
Answer:
M
83. main( )
{
int a[2][3][2] = {{{2,4},{7,8},{3,4}},{{2,2},{2,3},{3,4}}};
printf(“%u %u %u %d \n”,a,*a,**a,***a);
printf(“%u %u %u %d \n”,a+1,*a+1,**a+1,***a+1);
}
Answer:
100, 100, 100, 2
114, 104, 102, 3
84. main( )
{
int a[ ] = {10,20,30,40,50},j,*p;
for(j=0; j<5 br="" j="">{
printf(“%d” ,*a);
a++;
}
p = a;
for(j=0; j<5 br="" j="">{
printf(“%d ” ,*p);
p++;
}
}
Answer:
Compiler error: lvalue required.
.
85. main( )
{
16
static int a[ ] = {0,1,2,3,4};
int *p[ ] = {a,a+1,a+2,a+3,a+4};
int **ptr = p;
ptr++;
printf(“\n %d %d %d”, ptr-p, *ptr-a, **ptr);
*ptr++;
printf(“\n %d %d %d”, ptr-p, *ptr-a, **ptr);
*++ptr;
printf(“\n %d %d %d”, ptr-p, *ptr-a, **ptr);
++*ptr;
printf(“\n %d %d %d”, ptr-p, *ptr-a, **ptr);
}
Answer:
111
222
333
344
86. pointers are of a) integer data type b) character data type c) unsigned integer data type d) none of these
87. main( )
{
void *vp;
char ch = ‘g’, *cp = “goofy”;
int j = 20;
vp = &ch;
printf(“%c”, *(char *)vp);
vp = &j;
printf(“%d”,*(int *)vp);
vp = cp;
printf(“%s”,(char *)vp + 3);
}
Answer:
g20fy
88. main ( )
{
static char *s[ ] = {“black”, “white”, “yellow”, “violet”};
char **ptr[ ] = {s+3, s+2, s+1, s}, ***p;
p = ptr;
**++p;
printf(“%s”,*--*++p + 3);
}
Answer:
17
ck