ASP.net 3.5 interview questions

Thursday 26 May 2011


ASP.NET 3.5 Interview Questions & Answers :





1. Explain the life cycle of an ASP .NET page.?
Following are the events occur during ASP.NET Page Life Cycle:

1)Page_PreInit
2)Page_Init
3)Page_InitComplete
4)Page_PreLoad
5)Page_Load
6)Control Events
7)Page_LoadComplete
8)Page_PreRender
9)SaveViewState
10)Page_Render
11)Page_Unload

Among above events Page_Render is the only event which is raised by page. So we can't write code for this event.

2. how does the cookies work in asp.net?
we know Http is an state-less protocol which is required for interaction between clinet and server .

so there is an need to remeber state of request raised by an web browser so that
web server can recognize you have already previously visited or not.

There are two types of state management techniques:
a) Client side state management
b) Server - side statemanagement

Using cookies comes under clinet side statemanagement .In HttpResponse we write
Cookie containing sessionId and other information within it.

when a browser made a request to the web server the same cookie is sent to the server where server recognize the session id and get other information stored to it previously.

3. What is Ispostback method in ASP.Net? Why do we use that??

Basically Post back is an action performed by a interactive Webpage. When it goes to the server side for a non-client Operation Server again posts it back to the client and hence the name.
Ex:

if(!IsPostBack)

will not allow the page to post back again n again bcoz it reduces the performance.

4. Can User Control be stored in library?.
I will say "NO"

there are 3 types of controls:
1) User Control
2) Custom Control
3) Web parts

you can reuse User control in the current project in which you have built it, but you can't move it to other project as unless you just copy paste the same file there and make the changes for that project ( which violets the concept of library).

but custom control can be shared between projects. and you can precompile them even as a dll, so this means you can use them in library of any type.

5. what is the difference between application state and caching?
Application Object and Cached Object both falls under Server side State Management.

Application object resides in InProc i.e. on the same server where we hosted our application.
Cache Object resides on server side/ DownStream/Client Side.

Application Object will be disposed once application will stop.
Cache Object can be disposed using Time based cache dependency.

Only one user can access Application Object at a time hence we have to lock it every time we modify it.

6. what is boxing and unboxing?
Boxing is what happens when a value-type object is assigned to a reference-type variable.
Unboxing is what happens when a reference-type variable is assigned to a value-type variable.


7. What are the uses of Reflection??
Reflection is a concept using which we can

1) Load assemblies dynamically
2) Invoke methods at runtime
3) Retriving type information at runtime.

8. What is the use of AutoWireup in asp.net?
AutoEventWireup attribute is used to set whether the events needs to be automatically generated or not.
In the case where AutoEventWireup attribute is set to false (by default) event handlers are automatically required for Page_Load or Page_Init. However when we set the value of the AutoEventWireup attribute to true the ASP.NET runtime does not require events to specify event handlers like Page_Load or Page_Init.

9. what events will occur when a page is loaded?
Below are the events occures during page load.

1) Page_PreInit
2) Page_Init
3) Page_InitComplete
4) Page_PreLoad

10. Where is the View state Data stored?
ViewState data is stored in the hidden field. When the page is submitted to the server the data is sent to the server in the form of hidden fields for each control. If th viewstate of the control is enable true the value is retained on the post back to the client when the page is post backed.

11. What is the difference between custom web user control and a custom web server control?
Web User Control:
1) Easy to Create.
2) It Can be used inside the same Application.(To use it in other application we need to add it to that project.)
3) It Can take advantage of Caching Technique.

Web Server Control:
1) Bit tuff to create as compare to User Control.
2) Easy to use.
3) Can be added to ToolBox.

12. Where do the Cookie State and Session State information be stored?
Cookie Information will be stored in a txt file on client system under a
folder named Cookies. Search for it in your system you will find it.
Coming to Session State
As we know for every process some default space will be allocated by OS.
In case of InProc Session Info will be stored inside the process where our
application is running.
In case of StateServer Session Info will be stored using ASP.NET State Service.
In case of SQLServer Session info will be stored inside Database. Default DB
which will be created after running InstallSQLState Script is ASPState.
13. What is the difference between adding reference in solution Explorer and adding references by USING ?
Adding reference in solution explorer is used to add the DLL for that project for reference only. If you want to utilize that DLL methods/functions in our aspx.cs/.cs file etc you must write using that nameclass library name in file.

14. What are the different types of sessions in ASP.Net? Name them.?
Session Management can be achieved in two ways

1)InProc
2)OutProc

OutProc is again two types
1)State Server
2)SQL Server

InProc
Adv.:
1) Faster as session resides in the same process as the application
2) No need to serialize the data
DisAdv.:
1) Will degrade the performance of the application if large chunk of data is stored
2) On restart of IIS all the Session info will be lost
State Server
Adv.:
1) Faster then SQL Server session management
2) Safer then InProc. As IIS restart
won't effect the session data
DisAdv.:
1) Data need to be serialized
2) On restart of ASP.NET State Service session info will be lost
3)Slower as compared to InProc
SQL Server
Adv.:
1) Reliable and Durable
2) IIS and ASP.NET State Service
restart won't effect the session data
3) Good place for storing large chunk of data
DisAdv.:
1) Data need to be serialized
2) Slower as compare to InProc and State Server
3)Need to purchase Licensed
version of SQL Serve
15. How do you design a website with multilingual support in ASP.NET?
Multilingual website can be created using Globalization and Localization.
Using Globalization we change the Currency Date Numbers etc to Language Specific Format.
To change the string which is there in the label button etc to language specific string we use Localization.
In Localization we have to create different Resource files for different languages.
During this process we use some classes present in System.Resources System.Globalization System.Threading namespaces.
16. What is caching? What are different ways of caching in ASP.NET?
Caching is a technique of persisting the data in memory for immediate access to requesting program calls. This is considered as the best way to enhance the performance of the application.

Caching is of 3 types:
Output Caching - Caches the whole page.
Fragment Caching - Caches a part of the page
Data Caching - Caches the data

17. What is meant by 3-tier architecture.
We generally split our application into 3-Layers
1)Presentation Layer ( Where we keep all web forms Master Pages and User Controls).
2)Business Layer (Where we keep business logic). e.g Code related to manipulating data Custom Exception classes Custom Control classes Login related code if any etc. etc.
3)Data Access Layer (Where we keep code used to interact with DB). e.g. We can have the methods which are using SQL Helper (Application Block).
18. Explain the basic functionality of garbage collector?
Garbage Collector in .Net Framework is used for Automatic Memory Management i.e. it is collect all unused memory area and give to application. system.gc.collect() is a method for release the memory. But remember one think it is only an request i.e. we can't explicitly release the memory by using system.gc.collect().
19. What is the difference between mechine.config and web.config?
machine.config is a system level configuration i.e it is applied on all application in o/s that the configuration is set where as in web.config it is applicable to only one application i.e each asp.net webapplication will contain atleast on web.config file.
20. How can exception be handled with out the use of try catch?
using Exception Management application block
or
Page_error
Application_error objects
21. What is the difference between Response.Redirect and Server.Transfer.
Server.Transfer transfers page processing from one page directly to the next page without making a round-trip back to the client's browser. This provides a faster response with a little less overhead on the server.Server.Transfer does not update the clients url history list or current url.
Response.Redirect is used toredirect the user's browser to another page or site. This performs a trip back to the client where the client's browser is redirected to the new page. The user's browser history list is updated to reflect the new address.
22. Where the assembly is stored in asp.net?.
private are stored in application / bin directory and public are stored in GAC.
23. How we implement Web farm and Web Garden concept in ASP.NET?.
A web farm is a multi-server scenario. So we may have a server in each state of US. If the load on one server is in excess then the other servers step in to bear the brunt.
How they bear it is based on various models.
1. RoundRobin. (All servers share load equally)
2. NLB (economical)
3. HLB (expensive but can scale up to 8192 servers)
4. Hybrid (of 2 and 3).
5. CLB (Component load balancer).
A web garden is a multi-processor setup. i.e. a single server (not like the multi server above).
How to implement webfarms in .Net:
Go to web.config and
Here for mode you have 4 options.
a) Say mode inproc (non web farm but fast when you have very few customers).
b) Say mode StateServer (for webfarm)
c) Say mode SqlServer (for webfarm)
Whether to use option b or c depends on situation. StateServer is faster but SqlServer is more reliable and used for mission critical applications.
How to use webgardens in .Net:
Go to web.config and
Change the false to true. You have one more attribute that is related to webgarden in the same tag called cpuMask.
24. Is there any limit for query string? means what is the maximum size?..
Servers should be cautious about depending on URI lengths above 255 bytes because some older client or proxy implementations may not properly support these lengths.
Query string length depends on browser compatability

IE supports upto 255
Firefox supports upto 4000
25. What is the exact purpose of http handlers?
ASP.NET maps HTTP requests to HttpHandlers. Each HttpHandler enables processing of individual HTTP URLs or groups of URL extensions within an application. HttpHandlers have the same functionality as ISAPI extensions with a much simpler programming model
Ex
1.Default HttpHandler for all ASP.NET pages ->ASP.NET Page Handler (*.aspx)
2.Default HttpHandler for all ASP.NET service pages->ASP.NET Service Handler (*.asmx)
An HttpHandler can be either synchronous or asynchronous. A synchronous handler does not return until it finishes processing the HTTP request for which it is called. An asynchronous handler usually launches a process that can be lengthy and returns before that process finishes
After writing and compiling the code to implement an HttpHandler you must register the handler using your application's Web.config file.

26 .What is the Global.asax used for?
The Global.asax (including the Global.asax.cs file) is used to implement application and session level events.

27. What’s a bubbled event?
When you have a complex control, like DataGrid, writing an event processing routine for each object (cell, button, row, etc.) is quite tedious. The controls can bubble up their eventhandlers, allowing the main DataGrid event handler to take care of its constituents.

28 . What are the new features of .NET 3.5?
Main new features of .NET 3.5 are :
a)VS 2008 Multi-Targeting Support
b)In Built AJAX support for ASP.NET
c)LINQ Support
d)JavaScript Debugging Support
e)Nested Master Page Support
f)LINQ Intellisense and Javascript Intellisense support
g)Organize Imports or Usings support
h)Intellisense Filtering support
i)Visual Studio 2008 Split View
j)Debugging .NET Framework Library Source Code support


29 .           

WCF

Tuesday 17 May 2011

Q1. What is WCF?
WCF stands for Windows Communication Foundation. It is a Software development kit for developing services on Windows. WCF is introduced in .NET 3.0. in the System.ServiceModel namespace. WCF is based on basic concepts of Service oriented architecture (SOA)

Q2. What is endpoint in WCF service?
The endpoint is an Interface which defines how a client will communicate with the service. It consists of three main points: Address,Binding and Contract.

Q3. Explain Address,Binding and contract for a WCF Service?
Address:Address defines where the service resides.
Binding:Binding defines how to communicate with the service.
Contract:Contract defines what can be done with the service.

Q4. What are the various address format in WCF?
a)HTTP Address Format:--> http://localhost:
b)TCP Address Format:--> net.tcp://localhost:
c)MSMQ Address Format:--> net.msmq://localhost:

Q5. What are the types of binding available in WCF?
A binding is identified by the transport it supports and the encoding it uses. Transport may be HTTP,TCP etc and encoding may be text,binary etc. The popular types of binding may be as below:
a)BasicHttpBinding
b)NetTcpBinding
c)WSHttpBinding
d)NetMsmqBinding

Q6. What are the types of contract available in WCF?
The main contracts are:
a)Service Contract:Describes what operations the client can perform.
b)Operation Contract : defines the method inside Interface of Service.
c)Data Contract:Defines what data types are passed
d)Message Contract:Defines wheather a service can interact directly with messages

Q7. What are the various ways of hosting a WCF Service?
a)IIS b)Self Hosting c)WAS (Windows Activation Service)

Q8. WWhat is the proxy for WCF Service?
A proxy is a class by which a service client can Interact with the service.
By the use of proxy in the client application we are able to call the different methods exposed by the service


Q9. How can we create Proxy for the WCF Service?
We can create proxy using the tool svcutil.exe after creating the service.
We can use the following command at command line.
svcutil.exe *.wsdl *.xsd /language:C# /out:SampleProxy.cs /config:app.config

Q10.What is the difference between WCF Service and Web Service?
a)WCF Service supports both http and tcp protocol while webservice supports only http protocol.
b)WCF Service is more flexible than web service.
 
 

asp.net 2+ interview questions

Monday 16 May 2011

1 What is the difference between a Thread and Process?

A process is a collection of virtual memory space, code, data, and system resources. A thread is code that is to be serially executed within a process. A processor executes threads, not processes, so each application has at least one process, and a process always has at least one thread of execution, known as the primary thread. A process can have multiple threads in addition to the primary thread. Prior to the introduction of multiple threads of execution, applications were all designed to run on a single thread of execution.

When a thread begins to execute, it continues until it is killed or until it is interrupted by a thread with higher priority (by a user action or the kernel’s thread scheduler). Each thread can run separate sections of code, or multiple threads can execute the same section of code. Threads executing the same block of code maintain separate stacks. Each thread in a process shares that process’s global variables and resources.

2 Differance bettween Exe and DLL?

 EXE files are self executable files which can be directly run by the CPU. When we build our application it creates a .exe file.

DLL is otherwise known as class libraries. These are nothing but some class defined to do a particular job and we can use these DLLs in our application for our convenience.

Sql Server Interview questions part 2

Sunday 27 March 2011

12 .what is Constraint? How many types of constraints in SQL ?


Constraints are the way by Databse managing the data inegrity.
 
Types of constraint are:-
1)NOT Null
2)Default
3)Check
4)Rule
5)Primary
6)Unique
7)Foreign
 
 
 
13. CLR Integration ? what is Notification services 
 
Common Language Runtime (CLR ) in .NET applications using SQL Server 2005.
   Notification Services was designed to ease the pain of developing and 
deploying notification applications that generate personalized, timely information to
subscriber.
 
14.  differance between sql server 2000 and 2005?
1.sql server 2005 include interprise manger and 
queryanalyser together in same window we can open
many windowtabs in same place but in 2000 it is in different.
2. sql server 2005 support more new datatype like xml
3. we can make more database 2(paw(20))-1 in 2005 in
compareto 2000 where not possible so much database
4. in storeprocedure we can write try catch statemenet in2005 not in 2000 
 
 
15. 14.   SQL QUERY :::::  
2 Tables will be there Namely Employee having columns like 
Empid,Empname,Salary,Mgrid. Phone  Table having Empid and Phone number.
 Based on these some questions like this
 1) select all the Employees who 
does not have phone? 
2)Dispaly all managers from 
table(Manager id is same as Empid)
 3)How to know How many tables contain Empno as a column in database? 
4)Find duplicate rows in a table or if we have table with one column
which has many records which are not distinct. 
How to find out the distinct values from that column and number 
  of times it's repeated?
 5) How to delete the rows which are duplicate?
(Don't remove both duplicate records.)
 6)How to find the 6th highest salary?
   ANS:   
1) select all the Employees who does not have phone? 
select * from employees where empid not in (select empid from phone)
 2)Dispaly all managers from table(Manager id is same as Empid) 
select * from employees emp where emp.employeeid = emp.mgrid 
3)How to know How many tables contain Empno as a column in database? 
 select count(c.name) as Tables,c.name as Empno fromtest.sys.tables 
as t inner join test.sys.columns as c  onc.object_id=t.object_id 
and c.name='Empno' group by c.namehaving count (c.name) > 0 4)
Find duplicate rows in a table or if we have table with one column which 
has many records which are not distinct. How to find out the distinct 
values from that column and number  of times it's repeated? select 
salary,count(salary) as Repeat from employees group by salary 
having salary > 1 5) How to delete the rows which are duplicate?
 
(Don't remove both duplicate records.)WITH [T ORDERED BY ROWID] AS (SELECT ROW_NUMBER() OVER (ORDER BY product_name ASC) AS ROWID, * FROM product where product_name ='Scale') DELETE FROM [T ORDERED BY ROWID] WHERE ROWID <> 1 6)How to find the 6th highest salary? SELECT TOP 1 salary FROM ( SELECT DISTINCT TOP 6 salary FROM employee ORDER BY salary DESC) a ORDER BY salary   13. 

What is the differnce between view and materialized view
Answer
# 1
A view will takes the output of the query. But a materialized 
view stores the output of the query which is not possible in 
view

  14. 
What is the difference between UNIQUE KEY and UNIQUE INDEX?
Answer
# 1
Unique Index and Unique Constraint are the same. They 
achieve same goal. SQL Performance is same for both.
 
Add Unique Constraint
ALTER TABLE dbo.<tablename> ADD CONSTRAINT
<namingconventionconstraint> UNIQUE NONCLUSTERED
(
<columnname>
) ON [PRIMARY]
 
Add Unique Index
CREATE UNIQUE NONCLUSTERED INDEX
<namingconventionconstraint> ON dbo.<tablename>
(
<columnname>
) ON [PRIMARY]
 
There is no difference between Unique Index and Unique 
Constraint. Even though syntax are different the effect is 
the same. Unique Constraint creates Unique Index to 
maintain the constraint to prevent duplicate keys. Unique 
Index or Primary Key Index are physical structure that 
maintain uniqueness over some combination of columns across 
all rows of a table. It is a convenient way to enforce a 
Unique Constraint for SQL Server.

 15.
Suppose take my name "Reddyvaraprasad" From source it is coming Reddy vara prasad Need to get As Reddyvara prasad/
Answer
# 1
select Replace('Reddyvaraprasad','vara','vara ')

 16. 
How to count the no of records of a table without using COUNT function?
Answer
# 3
select max(rownum) from table_name;

 17. QUESTION       write a query to remove  null following table areid    name101   dineshnull  jyothinull  bharathi102   sureshnull  shilpha103   prakeshnull   suma i want the output format like id     name101    dinesh102    suresh103    prakesh   ANS: select * from table where id is not null;   18.QUESTION:  wirte a query  to remove null? following table are col1   col2   col3dinesh null   nullnull   suresh  nullnull   null   rakesh   want the output like  col1    col2    col3dinesh  suresh   prkaesh ANS: 1
wirte a query to remove null? following table are col1 col2 col3 dinesh null null null suresh null null null prakesh i want the output like col1 col2 col3 dinesh suresh prkaesh
Answer
# 1
select max(col1) col1,max(col2) col2,max(col3) col3
from table;
 
 
col1    col2    col3
dinesh  suresh   prkaesh

  ANS 2
wirte a query to remove null? following table are col1 col2 col3 dinesh null null null suresh null null null prakesh i want the output like col1 col2 col3 dinesh suresh prkaesh
Answer
# 2
SELECT DISTINCT((SELECT COL1 FROM COLL WHERE COL1<>'NULL')),(SELECT COL2 FROM COLL WHERE COL2<>'NULL'),(SELECT COL3 FROM COLL WHERE COL3<>'NULL')
FROM COLL

  19. Question       write a query   filter the null value data following source?name  agejohn  30smith nullnull  24sharp 35i want output name agejohn 30sharp 35 ANS:  
Re: write a query filter the null value data following source? name age john 30 smith null null 24 sharp 35 i want output name age john 30 sharp 35
Answer
# 1
select * from test_1 where name is not null and age is not 
null;

  20.  
What are Global Temporary tables
Answer
# 3
Global temporary tables belongs to that session only
 
create global temporary table test_gbl
( l_number_no number,
  l_char_vc   varchar2(100)
) [on commit delete rows]
 
ON COMMIT DELETE ROWS:- It's a default one
If any commit will issued that total data of a table will
losses. But table is exit
 
To overcome this we have option
ON COMMIT PRESERVE ROWS:-
means, If commit will issue the data of a table willn't loss
up to end of the session. Is session ends the data will losses.
 

    21. 
What is the Query to print out the individual total number of duplicate row in sql.
Answer
# 1
ANS:
 
SELECT department_id,COUNT(department_id) AS "Occurrences"
FROM departments
GROUP BY department_id
HAVING ( COUNT(department_id) > 1 )
 
DEPARTMENT_ID Occurrences
-------------   -----------
80         2
60         3
 
--In my 'departments' table , i have not assigned department_id column as a "primary key / unique key"

   22.
What is the diff between Truncate table / delete <table name> purge
Answer
# 1
TRUNCATE:-IT WILL DELETE ALL THE EXISTING RECORDS IN A TABLE
 
SYNTAX:-TRUNCATE TABLE <TABLE NAME>
 
DELETE:-IT WILL DELETE THE RECORDS IN A TABLE DEPENDINFG ON 
THE GIVEN CONDITION.
 
SYNTAX:-DELETE FROM <TABLE NAME> WHERE <CONDITON>
 
 
PURGE:-AFTER PERFOMING DROP OPERATION THE TABLES WILL STORE 
AT UNDO LOGS SO TO DELETE THE DATA COMPLETELY FROM TAHE 
DATA BASE WE WILL PURGE THE RECYCLEBIN.
 
SYNTAX:-PURGE RECYCLEBIN.

 23. 
What is the result, when NULL is compared with NULL?
Answer
# 4
The answer is NULL vs NULL = FALSE

 
Re: What is the result, when NULL is compared with NULL?
Answer
# 3
if we check a Null value with another Null value as equal, 
the result will be false.

24.
CAN U CREATE A PRIMARY KEY WITH OUT UNIQUE INDEX.
Answer
# 1
YES WE CAN CREATE. FIRST CREATE NON UNIQUE INDEX THEN 
CREATE PRIMARY KEY.

25.
Types of joins?
Answer
# 3
1. Self Join
Self join is a query in which a table is Joined to itself.
 
Self joins are used to compare the values in a column to 
the other values in the same column in the same table.
 
2.Equi Join or Inner join
Equi join is a join in which the rows are retrieved the 
equality of the relation ship between columns in the tables.
 
Select only those rows that have values in common in the 
columns specified in the ON clause.
 
3.Non Equi Join or Outer Join
 
Left Outer Join:
 
Retrieves the matching records in both the table and non 
matching records in the first or left table.
Right Outer Join
 
retrieves the matching records in both the table and non 
matching records in the second or the right table.
 
Full Outer Join
 
Retrieves all the records (means matching and non matching 
records in both the tables).
 

26.
IF i write before / after insert / update trigger and i do rollback what will happen?
Answer
# 1
A trigger May Not issue A TCL statement like COMMIT,ROLLBACK,SAVEPOINT.
So U Cant Write A TCL Command Inside A trigger.

27.
What is different between union and minus?
Answer
# 1
Let's consider the difference between Minus and Union using 
following examples.
 
1.create TABLE A AND B With similar structure
2.insert records in Table A and B.
3.Keep some records identical(here 2 rows).
4.find out the difference betwn 2 looking into the output.
 
 
CREATE TABLE A(NAME VARCHAR2(30));
  INSERT INTO A VALUES('A');
   INSERT INTO A VALUES('B');
   INSERT INTO A VALUES('C');
   INSERT INTO A VALUES('D');
COMMIT;
CREATE TABLE B(NAME VARCHAR2(30));
INSERT INTO b VALUES('A')
INSERT INTO b VALUES('B')
INSERT INTO b VALUES('Y')
INSERT INTO b VALUES('X')
COMMIT;
 
 
 
1) SELECT * FROM A
MINUS
SELECT * FROM B
 
NAME                          
------------------------------
C                             
D                             
2 rows selected
 
 
 
2)SELECT * FROM A
UNION
SELECT * FROM B
 
 
NAME                          
------------------------------
A                             
B                             
C                             
D                             
Y                             
x                             
6 rows selected


Re: What is different between union and minus?
Answer
# 2
 
unoin:- This operator returns from all the queries(combined
through union) but not duplicate record will be display.
ex- A={1,2,3,4}
    B={2,3,4,5}
AUB={1,2,3,4,5}............
 
Minus:- This operator displays records which belongs to only
the first query.
ex:- A={1,2,3,4}
     B= {2,3,5}
A-B={1,4}...................

28.
What is a transaction?
Answer
# 2
It starts with a first executable statement and ends when 
commit or rollback statement occurs.

29.
What is difference between CHAR and VARCHAR2?What is the maximum SIZE allowed for each type?
Answer
# 1
VARCHAR2(size):variable lenght character data maximum size 
is 4000 and minimum is 1
char2(size):fixed lenght character data of lenght size bytes
minimum and default is 1 and maximum is 2000.
 

30. 
how u can find the n row from a table?
Answer
# 6
select *
from employees
where  rowid=(select max(rowid) a 
from employees)

 

Sql Server Interview questions part 1

Saturday 26 March 2011

http://www.allinterview.com/Interview-Questions/SQL-PLSQL.html
1. wat new abt truncate in sql server ?

Ans: 
While using TRUNCATE stmt, WHERE clause can not be used.
When we use TRUNCATE stmt, Trigger does not get fire. After
using TRUNCATE stmt, all the deleted rows are not entered in
the transaction log file(.ldf)

2.
how to find the second salary?
Answer
# 10
Here we can find out 2nd highest salary in many ways,
according to the situation we can select anyone…
1st Type:
select min(esal) from emp where esal in (select top 2 esal
from emp order by esal desc)

2nd Type:
select max(esal) from emp where esal not in(select max(esal)
from emp)

3rd Type:
select max(esal) from emp where esal <(select max(esal) from
emp )

4th Type:
select Max(esal) from EMP a where 2=(select
COUNT(distinct(esal)) from EMP b where a.eSAL<=b.eSAL);


3.
Re: Advantages and disadvantages of stored procedures.
Answer
# 1
The only disadvantage I see with Stored-procs is that we
cannot use them with select statements.
 


4.
how many instance use in sql server 2005
Answer
# 1
normally sql sever 2000 16 instance possible
 in 2005 50 instance possible

5.
Re: In join, which clause in not used?
Answer
# 1
Order Clause is not used in joining two tables.


6.
What is Peer to peer Replication?
Answer
# 1
Peer-to-peer replication (also known as multimaster 
replication) is a configuration that has the following 
characteristics: 

Replication occurs between tables on two or more servers. 
Updates on any one server are replicated to all other 
associated servers. 
Applications on any of the servers can update the same rows 
and columns in those tables at the same time. 
All servers are equal peers with equal ownership of the 
data; no server is the "master" or source owner of the 
data.

7.
I have to display ten columns values from diffrent ten tables. how many joins are require?
Answer
# 7
there are 3 answeres
1. No joins are required if do not want to display related 
data
2.  9 joins are requred if all tables are related
3. no joins reuquired  we can use union if condition is 
like following
select cola from a
union 
select colb from b
union
select colc from c
.
.
.
like wise ten statements


8 .
i have table students with fields classname,studname
select * from students
classname  studname
1           xxxxx
1           yyyy
1           zzzz
2            qqqq
2             tttt
3             dsds
3             www
i want the output should be

No of students in class 1 : 3
No of students in class 2 : 2
No of students in class 3 : 2 
 
ANS: 
  select 'No of students in class '+ CONVERT(VARCHAR,ClassName)+' : '+ convert(varchar,Count(studname))  from students 
group by Classname order by classname  

9..

how to update a null value field in sql server

eg
a table contains 3 fields id,name,salary
and 3 records 
salary of 1 record is null 
i want update the nullfield

111 arun 300
112 ddd  200
113 ttt null
i want to update table with add 100 to every record include null
after updation 
the recrds should be
111 arun 400
112 ddd  300
113 ttt 100 
 
ANS:  create table #temp (eid int, names varchar(10),sal int)

insert into #temp values (111, 'arun', 300)
insert into #temp values(112, 'ddd', 200)

insert into #temp values(113,'ttt',null)

select * from #temp 

update #temp 
set sal = isnull(sal,0)+ 100

select * from #temp
 
ANS2:  
 
  update tablename set salary=100 where salary is null

10.
What is cursor ? And what is difference between Trigger ?
Answer
# 2
Cursor is a database object used by applications to 
manipulate data in a set on a row-by-row basis, instead of 
the typical SQL commands that operate on all the rows in 
the set at one time. 


Trigger is a database object invoked automatically when any 
event occured.
These aevents are 
Delete, Insert, Update etc....

SQL server store the intermediate data into to dummy table 
INSERTED and DELETED...

At the time of insert operation SQL Server STores inserted 
rows into the INSERTED table and at the time of delete or 
update SQL Server stores the information into DELETED dummy 
table


11. 
how to delete duplicate rows from table in sql server
 
ANS 1  
delete  tblname where columname  in (select columnname 
FROM  tblname  GROUP BY  columnname having count(columnname)
>=2)
 
ANS 2
CREATE TABLE dbo.duplicateTest      ------Deleting
Duplicates with same id 
( 
[ID] [int] , 
[FirstName] [varchar](25), 
[LastName] [varchar](25)  
) ON [PRIMARY] 

INSERT INTO dbo.duplicateTest VALUES(1, 'Bob','Smith') 
INSERT INTO dbo.duplicateTest VALUES(2, 'Dave','Jones') 
INSERT INTO dbo.duplicateTest VALUES(3, 'Karen','White') 
INSERT INTO dbo.duplicateTest VALUES(1, 'Bob','Smith') 



SELECT * FROM dbo.duplicateTest 

SET ROWCOUNT 1 
DELETE FROM dbo.duplicateTest WHERE ID = 1 
SET ROWCOUNT 0 

SELECT * FROM dbo.duplicateTest 

Drop table dbo.duplicatetest




































































































































































































100 Multiple choice questions in C

Monday 14 March 2011

100 Multiple choice questions in C

 /*question number 1*/

Code:
int z,x=5,y=-10,a=4,b=2; 
z = x++ - --y * b / a;
What number will z in the sample code above contain?
Choice 1
5
Choice 2
6
Choice 3
10 [Ans] Corrected by buddy by running the program
Choice 4
11
Choice 5
12
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

/*question number 2*/
With every use of a memory allocation function, what function should be used to release allocated memory which is no longer needed?
Choice 1
unalloc()
Choice 2
dropmem()
Choice 3
dealloc()
Choice 4
release()
Choice 5
free() [Ans]
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

/*question number 3*/
Code:
void *ptr;
myStruct myArray[10];
ptr = myArray;
Which of the following is the correct way to increment the variable "ptr"?
Choice 1
ptr = ptr + sizeof(myStruct); [Ans]
Choice 2
++(int*)ptr;
Choice 3
ptr = ptr + sizeof(myArray);
Choice 4
increment(ptr);
Choice 5
ptr = ptr + sizeof(ptr);
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

/*question number 4*/
Code:
char* myFunc (char *ptr)
{
 ptr += 3;
 return (ptr);
} 
int main()
{
 char *x, *y;
 x = "HELLO";
 y = myFunc (x);
 printf ("y = %s \n", y);
 return 0;
}
What will print when the sample code above is executed?
Choice 1
y = HELLO
Choice 2
y = ELLO
Choice 3
y = LLO
Choice 4
y = LO [Ans]
Choice 5
x = O
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

/*question number 5*/
Code:
struct node *nPtr, *sPtr;    /* pointers for a linked list. */ 
for (nPtr=sPtr; nPtr; nPtr=nPtr->next)
{    
 free(nPtr);
}
The sample code above releases memory from a linked list. Which of the choices below accurately describes how it will work?
Choice 1
It will work correctly since the for loop covers the entire list.
Choice 2
It may fail since each node "nPtr" is freed before its next address can be accessed.
Choice 3
In the for loop, the assignment "nPtr=nPtr->next" should be changed to "nPtr=nPtr.next".
Choice 4
This is invalid syntax for freeing memory.
Choice 5
The loop will never end.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

/*question number 6*/
What function will read a specified number of elements from a file?
Choice 1
fileread()
Choice 2
getline()
Choice 3
readfile()
Choice 4
fread()
Choice 5
gets()
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

/*question number 7*/
"My salary was increased by 15%!"
Select the statement which will EXACTLY reproduce the line of text above.
Choice 1
printf("\"My salary was increased by 15/%\!\"\n");
Choice 2
printf("My salary was increased by 15%!\n");
Choice 3
printf("My salary was increased by 15'%'!\n");
Choice 4
printf("\"My salary was increased by 15%%!\"\n");[Ans]
Choice 5
printf("\"My salary was increased by 15'%'!\"\n");
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

/*question number 8*/
What is a difference between a declaration and a definition of a variable?
Choice 1
Both can occur multiple times, but a declaration must occur first.
Choice 2
There is no difference between them.
Choice 3
A definition occurs once, but a declaration may occur many times.
Choice 4
A declaration occurs once, but a definition may occur many times. [Ans]
Choice 5
Both can occur multiple times, but a definition must occur first.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

/*question number 9*/
int testarray[3][2][2] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12};
What value does testarray[2][1][0] in the sample code above contain?
Choice 1
3
Choice 2
5
Choice 3
7
Choice 4
9
Choice 5
11[Ans]
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

/*question number 10*/
Code:
int a=10,b;
b=a++ + ++a;
printf("%d,%d,%d,%d",b,a++,a,++a);
what will be the output when following code is executed
Choice 1
12,10,11,13
Choice 2
22,10,11,13
Choice 3
22,11,11,11
Choice 4
12,11,11,11
Choice 5
22,13,13,13[Ans]
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

/*question number 11*/
Code:
int x[] = { 1, 4, 8, 5, 1, 4 }; 
int *ptr, y; 
ptr  = x + 4; 
y = ptr - x;
What does y in the sample code above equal?
Choice 1
-3
Choice 2
0
Choice 3
4[Ans]
Choice 4
4 + sizeof( int )
Choice 5
4 * sizeof( int
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

/*question number 12*/
Code:
void myFunc (int x) 
{ 
   if (x > 0)
   myFunc(--x); 
   printf("%d, ", x); 
} 
int main() 
{ 
   myFunc(5); 
   return 0; 
}
What will the above sample code produce when executed?
Choice 1
1, 2, 3, 4, 5, 5,
Choice 2
4, 3, 2, 1, 0, 0,
Choice 3
5, 4, 3, 2, 1, 0,
Choice 4
0, 0, 1, 2, 3, 4, [Ans]
Choice 5
0, 1, 2, 3, 4, 5,
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

/*question number 13*/
11 ^ 5
What does the operation shown above produce?
Choice 1
1
Choice 2
6
Choice 3
8
Choice 4
14 [Ans]
Choice 5
15
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

/*question number 14*/
#define MAX_NUM 15
Referring to the sample above, what is MAX_NUM?
Choice 1
MAX_NUM is an integer variable.
Choice 2
MAX_NUM is a linker constant.
Choice 3
MAX_NUM is a precompiler constant.
Choice 4
MAX_NUM is a preprocessor macro. [Ans]
Choice 5
MAX_NUM is an integer constant.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

/*question number 15*/
Which one of the following will turn off buffering for stdout?
Choice 1
setbuf( stdout, FALSE );
Choice 2
setvbuf( stdout, NULL );
Choice 3
setbuf( stdout, NULL );
Choice 4
setvbuf( stdout, _IONBF );
Choice 5
setbuf( stdout, _IONBF );
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

/*question number 16*/
What is a proper method of opening a file for writing as binary file?
Choice 1
FILE *f = fwrite( "test.bin", "b" );
Choice 2
FILE *f = fopenb( "test.bin", "w" );
Choice 3
FILE *f = fopen( "test.bin", "wb" );
Choice 4
FILE *f = fwriteb( "test.bin" );
Choice 5
FILE *f = fopen( "test.bin", "bw" );
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

/*question number 17*/
Which one of the following functions is the correct choice for moving blocks of binary data that are of arbitrary size and position in memory?
Choice 1
memcpy()
Choice 2
memset()
Choice 3
strncpy()
Choice 4
strcpy()
Choice 5
memmove()[Ans]
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

/*question number 18*/
int x = 2 * 3 + 4 * 5;
What value will x contain in the sample code above?
Choice 1
22
Choice 2
26[Ans]
Choice 3
46
Choice 4
50
Choice 5
70
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

/*question number 19*/
Code:
void * array_dup (a, number, size) 
  const void * a; 
  size_t number; 
  size_t size; 
{ 
  void * clone; 
  size_t bytes; 
  assert(a != NULL); 
  bytes = number * size; 
  clone = alloca(bytes); 
  if (!clone) 
    return clone; 
  memcpy(clone, a, bytes); 
  return clone; 
}
The function array_dup(), defined above, contains an error. Which one of the following correctly analyzes it?
Choice 1
If the arguments to memcpy() refer to overlapping regions, the destination buffer will be subject to memory corruption.
Choice 2
array_dup() declares its first parameter to be a pointer, when the actual argument will be an array.
Choice 3
The memory obtained from alloca() is not valid in the context of the caller. Moreover, alloca() is nonstandard.
Choice 4
size_t is not a Standard C defined type, and may not be known to the compiler.
Choice 5
The definition of array_dup() is unusual. Functions cannot be defined using this syntax.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

/*question number 20*/
int var1;
If a variable has been declared with file scope, as above, can it safely be accessed globally from another file?
Choice 1
Yes; it can be referenced through the register specifier.
Choice 2
No; it would have to have been initially declared as a static variable.
Choice 3
No; it would need to have been initially declared using the global keyword.[Ans]
Choice 4
Yes; it can be referenced through the publish specifier.
Choice 5
Yes; it can be referenced through the extern specifier.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

/*question number 21*/
time_t t;
Which one of the following statements will properly initialize the variable t with the current time from the sample above?
Choice 1
t = clock();[Ans]
Choice 2
time( &t );
Choice 3
t = ctime();
Choice 4
t = localtime();
Choice 5
None of the above
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

/*question number 22*/
Which one of the following provides conceptual support for function calls?
Choice 1
The system stack[Ans]
Choice 2
The data segment
Choice 3
The processor's registers
Choice 4
The text segment
Choice 5
The heap
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
/*question number 23*/
C is which kind of language?
Choice 1
Machine
Choice 2
Procedural[Ans]
Choice 3
Assembly
Choice 4
Object-oriented
Choice 5
Strictly-typed
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

/*question number 24*/
Code:
int i,j; 
int ctr = 0; 
int myArray[2][3]; 
for (i=0; i<3; i++) 
   for (j=0; j<2; j++) 
   { 
      myArray[j][i] = ctr; 
      ++ctr; 
   }
What is the value of myArray[1][2]; in the sample code above?
Choice 1
1
Choice 2
2
Choice 3
3
Choice 4
4
Choice 5
5 [Ans] 00,10,01,11,12
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

/*question number 25*/
Code:
int x = 0; 
for (x=1; x<4; x++); 
printf("x=%d\n", x);
What will be printed when the sample code above is executed?
Choice 1
x=0
Choice 2
x=1
Choice 3
x=3
Choice 4
x=4[Ans]
Choice 5
x=5
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

/*question number 26*/
Code:
int x = 3; 
if( x == 2 );
  x = 0; 
if( x == 3 )
 x++; 
else x += 2;
What value will x contain when the sample code above is executed?
Choice 1
1
Choice 2
2[Ans]
Choice 3
3
Choice 4
4
Choice 5
5
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

/*question number 27*/
Code:
char *ptr; 
char myString[] = "abcdefg"; 
ptr = myString; 
ptr += 5;
What string does ptr point to in the sample code above?
Choice 1
fg [Ans]/*because string*/
Choice 2
efg
Choice 3
defg
Choice 4
cdefg
Choice 5
None of the above
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

/*question number 28*/
Code:
double x = -3.5, y = 3.5; 
printf( "%.0f : %.0f\n", ceil( x ), ceil( y ) ); 
printf( "%.0f : %.0f\n", floor( x ), floor( y ) );
What will the code above print when executed?
ceil =>rounds up 3.2=4 floor =>rounds down 3.2=3
Choice 1
-3 : 4
-4 : 3 [Ans]
Choice 2
-4 : 4
-3 : 3
Choice 3
-4 : 3
-4 : 3
Choice 4
-4 : 3
-3 : 4
Choice 5
-3 : 3
-4 : 4
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

/*question number 29*/
Which one of the following will declare a pointer to an integer at address 0x200 in memory?
Choice 1
int *x;
*x = 0x200;[Ans]
Choice 2
int *x = &0x200;
Choice 3
int *x = *0x200;
Choice 4
int *x = 0x200;
Choice 5
int *x( &0x200 );
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

/*question number 30*/
Code:
int x = 5; 
int y = 2; 
char op = '*'; 
switch (op) 
{ 
  default : x += 1; 
  case '+' : x += y; /*It will go to all the cases*/
  case '-' : x -= y; 
}
After the sample code above has been executed, what value will the variable x contain?
Choice 1
4
Choice 2
5
Choice 3
6 [Ans]
Choice 4
7
Choice 5
8
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

/*question number 31*/
Code:
x = 3, counter = 0; 
while ((x-1)) 
{ 
   ++counter; 
   x--; 
}
Referring to the sample code above, what value will the variable counter have when completed?
Choice 1
0
Choice 2
1
Choice 3
2[Ans]
Choice 4
3
Choice 5
4
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

/*question number 32*/
char ** array [12][12][12];
Consider array, defined above. Which one of the following definitions and initializations of p is valid?
Choice 1
char ** (* p) [12][12] = array; [Ans]
Choice 2
char ***** p = array;
Choice 3
char * (* p) [12][12][12] = array;
Choice 4
const char ** p [12][12][12] = array;
Choice 5
char (** p) [12][12] = array;
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

/*question number 33*/
void (*signal(int sig, void (*handler) (int))) (int);
Which one of the following definitions of sighandler_t allows the above declaration to be rewritten as follows:
sighandler_t signal (int sig, sighandler_t handler);
Choice 1
typedef void (*sighandler_t) (int);[Ans]
Choice 2
typedef sighandler_t void (*) (int);
Choice 3
typedef void *sighandler_t (int);
Choice 4
#define sighandler_t(x) void (*x) (int)
Choice 5
#define sighandler_t void (*) (int)
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

/*question number 34*/
All of the following choices represent syntactically correct function definitions. Which one of the following represents a semantically legal function definition in Standard C?
Choice 1
Code:
int count_digits (const char * buf) { 
  assert(buf != NULL); 
  int cnt = 0, i; 
  for (i = 0; buf[i] != '\0'; i++) 
    if (isdigit(buf[i])) 
      cnt++; 
  

 return cnt; 
}
Choice 2
Code:
int count_digits (const char * buf) { 
  int cnt = 0; 
  assert(buf != NULL); 
  for (int i = 0; buf[i] != '\0'; i++) 
    if (isdigit(buf[i])) 
      cnt++; 
  return cnt; 
}
Choice 3

Code:
int count_digits (const char * buf) { 
  int cnt = 0, i; 
  assert(buf != NULL); 
  for (i = 0; buf[i] != '\0'; i++) 
    if (isdigit(buf[i])) 
      cnt++; 
  return cnt; 
}
Choice 4

Code:
int count_digits (const char * buf) { 
  assert(buf != NULL); 
  for (i = 0; buf[i] != '\0'; i++) 
    if (isdigit(buf[i])) 
      cnt++; 
  return cnt; 
}
Choice 5

Code:
int count_digits (const char * buf) { 
  assert(buf != NULL); 
  int cnt = 0; 
  for (int i = 0; buf[i] != '\0'; i++) 
    if (isdigit(buf[i])) 
      cnt++; 
  return cnt; 
}
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

/*question number 35*/
struct customer *ptr = malloc( sizeof( struct customer ) );
Given the sample allocation for the pointer "ptr" found above, which one of the following statements is used to reallocate ptr to be an array of 10 elements?
Choice 1
ptr = realloc( ptr, 10 * sizeof( struct customer)); [Ans]
Choice 2
realloc( ptr, 9 * sizeof( struct customer ) );
Choice 3
ptr += malloc( 9 * sizeof( struct customer ) );
Choice 4
ptr = realloc( ptr, 9 * sizeof( struct customer ) );
Choice 5
realloc( ptr, 10 * sizeof( struct customer ) );
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

/*question number 36*/
Which one of the following is a true statement about pointers?
Choice 1
Pointer arithmetic is permitted on pointers of any type.
Choice 2
A pointer of type void * can be used to directly examine or modify an object of any type.
Choice 3
Standard C mandates a minimum of four levels of indirection accessible through a pointer.
Choice 4
A C program knows the types of its pointers and indirectly referenced data items at runtime.
Choice 5
Pointers may be used to simulate call-by-reference.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

/*question number 37*/
Which one of the following functions returns the string representation from a pointer to a time_t value?
Choice 1
localtime
Choice 2
gmtime
Choice 3
strtime
Choice 4
asctime
Choice 5
ctime
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

/*question number 38*/
Code:
short testarray[4][3] = { {1}, {2, 3}, {4, 5, 6} }; 
 printf( "%d\n", sizeof( testarray ) );
Assuming a short is two bytes long, what will be printed by the above code?
Choice 1
It will not compile because not enough initializers are given.
Choice 2
6
Choice 3
7
Choice 4
12
Choice 5
24 [Ans]
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

/*question number 39*/
char buf [] = "Hello world!";

char * buf = "Hello world!";
In terms of code generation, how do the two definitions of buf, both presented above, differ?
Choice 1
The first definition certainly allows the contents of buf to be safely modified at runtime; the second definition does not.
Choice 2
The first definition is not suitable for usage as an argument to a function call; the second definition is.
Choice 3
The first definition is not legal because it does not indicate the size of the array to be allocated; the second definition is legal.
Choice 4
They do not differ -- they are functionally equivalent. [Ans]
Choice 5
The first definition does not allocate enough space for a terminating NUL-character, nor does it append one; the second definition does.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

/*question number 40*/
In a C expression, how is a logical AND represented?
Choice 1
@@
Choice 2
||
Choice 3
.AND.
Choice 4
&& [Ans]
Choice 5
.AND
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

/*question number 41*/
How do printf()'s format specifiers %e and %f differ in their treatment of floating-point numbers?
Choice 1
%e always displays an argument of type double in engineering notation; %f always displays an argument of type double in decimal notation. [Ans]
Choice 2
%e expects a corresponding argument of type double; %f expects a corresponding argument of type float.
Choice 3
%e displays a double in engineering notation if the number is very small or very large. Otherwise, it behaves like %f and displays the number in decimal notation.
Choice 4
%e displays an argument of type double with trailing zeros; %f never displays trailing zeros.
Choice 5
%e and %f both expect a corresponding argument of type double and format it identically. %e is left over from K&R C; Standard C prefers %f for new code.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

/*question number 42*/
Which one of the following Standard C functions can be used to reset end-of-file and error conditions on an open stream?
Choice 1
clearerr()
Choice 2
fseek()
Choice 3
ferror()
Choice 4
feof()
Choice 5
setvbuf()
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

/*question number 43*/
Which one of the following will read a character from the keyboard and will store it in the variable c?
Choice 1
c = getc();
Choice 2
getc( &c );
Choice 3
c = getchar( stdin );
Choice 4
getchar( &c )
Choice 5
c = getchar(); [Ans]
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

/*question number 44*/
Code:
#include <stdio.h> 
int i; 
void increment( int i ) 
{ 
   i++; 
} 

int main() 
{ 
   for( i = 0; i < 10; increment( i ) ) 
   { 
   } 
   printf("i=%d\n", i); 
   return 0; 
}
What will happen when the program above is compiled and executed?
Choice 1
It will not compile.
Choice 2
It will print out: i=9.
Choice 3
It will print out: i=10.
Choice 4
It will print out: i=11.
Choice 5
It will loop indefinitely.[Ans]
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

/*question number 45*/
Code:
char ptr1[] = "Hello World"; 
char *ptr2 = malloc( 5 ); 
ptr2 = ptr1;
What is wrong with the above code (assuming the call to malloc does not fail)?
Choice 1
There will be a memory overwrite.
Choice 2
There will be a memory leak.
Choice 3
There will be a segmentation fault.
Choice 4
Not enough space is allocated by the malloc.
Choice 5
It will not compile.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

/*question number 46*/
Code:
int i = 4; 
switch (i) 
{ 
   default: 
      ; 
   case 3: 
      i += 5; 
      if ( i == 8) 
      { 
         i++; 
         if (i == 9) break; 
         i *= 2; 
      } 
      i -= 4; 
      break; 
   case 8: 
      i += 5; 
      break;
} 
printf("i = %d\n", i);
What will the output of the sample code above be?
Choice 1
i = 5[Ans]
Choice 2
i = 8
Choice 3
i = 9
Choice 4
i = 10
Choice 5
i = 18
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

/*question number 47*/
Which one of the following C operators is right associative?
Choice 1
= [Ans]
Choice 2
,
Choice 3
[]
Choice 4
^
Choice 5
->
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

/*question number 48*/
What does the "auto" specifier do?
Choice 1
It automatically initializes a variable to 0;.
Choice 2
It indicates that a variable's memory will automatically be preserved.[Ans]
Choice 3
It automatically increments the variable when used.
Choice 4
It automatically initializes a variable to NULL.
Choice 5
It indicates that a variable's memory space is allocated upon entry into the block.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

/*question number 49*/
How do you include a system header file called sysheader.h in a C source file?
Choice 1
#include <sysheader.h> [Ans]
Choice 2
#incl "sysheader.h"
Choice 3
#includefile <sysheader>
Choice 4
#include sysheader.h
Choice 5
#incl <sysheader.h>

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

/*question number 50*/
Which one of the following printf() format specifiers indicates to print a double value in decimal notation, left aligned in a 30-character field, to four (4) digits of precision?
Choice 1
%-30.4e
Choice 2
%4.30e
Choice 3
%-4.30f
Choice 4
%-30.4f [Ans] decimal notation
Choice 5
%#30.4f
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

/*question number 51*/
Code:
int x = 0; 
for ( ; ; ) 
{ 
 if (x++ == 4)
  break; 
 continue; 
} 
printf("x=%d\n", x);
What will be printed when the sample code above is executed?
Choice 1
x=0
Choice 2
x=1
Choice 3
x=4
Choice 4
x=5[Ans]
Choice 5
x=6
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

/*question number 52*/
According to the Standard C specification, what are the respective minimum sizes (in bytes) of the following three data types: short; int; and long?
Choice 1
1, 2, 2
Choice 2
1, 2, 4
Choice 3
1, 2, 8
Choice 4
2, 2, 4[Ans]
Choice 5
2, 4, 8
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

/*question number 53*/
Code:
int y[4] = {6, 7, 8, 9}; 
int *ptr = y + 2; 
printf("%d\n", ptr[ 1 ] );  /*ptr+1 == ptr[1]*/
What is printed when the sample code above is executed?
Choice 1
6
Choice 2
7
Choice 3
8
Choice 4
9[Ans]
Choice 5
The code will not compile.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

/*question number 54*/
penny = one
nickel = five
dime = ten
quarter = twenty-five
How is enum used to define the values of the American coins listed above?
Choice 1
enum coin {(penny,1), (nickel,5), (dime,10), (quarter,25)};
Choice 2
enum coin ({penny,1}, {nickel,5}, {dime,10}, {quarter,25});
Choice 3
enum coin {penny=1,nickel=5,dime=10,quarter=25};[Ans]
Choice 4
enum coin (penny=1,nickel=5,dime=10,quarter=25);
Choice 5
enum coin {penny, nickel, dime, quarter} (1, 5, 10, 25);
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

/*question number 55*/
char txt [20] = "Hello world!\0";
How many bytes are allocated by the definition above?
Choice 1
11 bytes
Choice 2
12 bytes
Choice 3
13 bytes
Choice 4
20 bytes[Ans]
Choice 5
21 bytes
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

/*question number 56*/
Code:
int i = 4; 
int x = 6; 
double z; 
z =  x / i; 
printf("z=%.2f\n", z);
What will print when the sample code above is executed?
Choice 1
z=0.00
Choice 2
z=1.00[Ans]
Choice 3
z=1.50
Choice 4
z=2.00
Choice 5
z=NULL
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

/*question number 57*/
Which one of the following variable names is NOT valid?
Choice 1
go_cart
Choice 2
go4it
Choice 3
4season[Ans]
Choice 4
run4
Choice 5
_what
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

/*question number 58*/
int a [8] = { 0, 1, 2, 3 };
The definition of a above explicitly initializes its first four elements. Which one of the following describes how the compiler treats the remaining four elements?
Choice 1
Standard C defines this particular behavior as implementation-dependent. The compiler writer has the freedom to decide how the remaining elements will be handled.
Choice 2
The remaining elements are initialized to zero(0).[Ans]
Choice 3
It is illegal to initialize only a portion of the array. Either the entire array must be initialized, or no part of it may be initialized.
Choice 4
As with an enum, the compiler assigns values to the remaining elements by counting up from the last explicitly initialized element. The final four elements will acquire the values 4, 5, 6, and 7, respectively.
Choice 5
They are left in an uninitialized state; their values cannot be relied upon.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

/*question number 59*/
Which one of the following is a true statement about pointers?
Choice 1
They are always 32-bit values.
Choice 2
For efficiency, pointer values are always stored in machine registers.
Choice 3
With the exception of generic pointers, similarly typed pointers may be subtracted from each other.
Choice 4
A pointer to one type may not be cast to a pointer to any other type.
Choice 5
With the exception of generic pointers, similarly typed pointers may be added to each other.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

/*question number 60*/
Which one of the following statements allocates enough space to hold an array of 10 integers that are initialized to 0?
Choice 1
int *ptr = (int *) malloc(10, sizeof(int));
Choice 2
int *ptr = (int *) calloc(10, sizeof(int));
Choice 3
int *ptr = (int *) malloc(10*sizeof(int)); [Ans]
Choice 4
int *ptr = (int *) alloc(10*sizeof(int));
Choice 5
int *ptr = (int *) calloc(10*sizeof(int));
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

/*question number 61*/
What are two predefined FILE pointers in C?
Choice 1
stdout and stderr
Choice 2
console and error
Choice 3
stdout and stdio
Choice 4
stdio and stderr
Choice 5
errout and conout
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

/*question number 62*/
Code:
u32 X (f32 f)
{ 
 union { 
        f32 f; 
        u32 n; 
       } u; 
 u.f = f; 
 return u.n; 
}
Given the function X(), defined above, assume that u32 is a type-definition indicative of a 32-bit unsigned integer and that f32 is a type-definition indicative of a 32-bit floating-point number.
Which one of the following describes the purpose of the function defined above?
Choice 1
X() effectively rounds f to the nearest integer value, which it returns.
Choice 2
X() effectively performs a standard typecast and converts f to a roughly equivalent integer.
Choice 3
X() preserves the bit-pattern of f, which it returns as an unsigned integer of equal size.
Choice 4
Since u.n is never initialized, X() returns an undefined value. This function is therefore a primitive pseudorandom number generator.
Choice 5
Since u.n is automatically initialized to zero (0) by the compiler, X() is an obtuse way of always obtaining a zero (0) value.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

/*question number 63*/
Code:
long factorial (long x) 
{ 
 ???? 
 return x * factorial(x - 1); 
}
With what do you replace the ???? to make the function shown above return the correct answer?
Choice 1
if (x == 0) return 0;
Choice 2
return 1;
Choice 3
if (x >= 2) return 2;
Choice 4
if (x == 0) return 1;
Choice 5
if (x <= 1) return 1; [Ans]{more probable}
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

/*question number 64*/
Code:
/* Increment each integer in the array 'p' of * size 'n'. */ 
void increment_ints (int p [/*n*/], int n) 
{ 
  assert(p != NULL);  /* Ensure that 'p' isn't a null pointer. */ 
  assert(n >= 0);  /* Ensure that 'n' is nonnegative. */ 
  while (n)  /* Loop over 'n' elements of 'p'. */ 
  { 
    *p++;          /* Increment *p. */ 
    p++, n--;      /* Increment p, decrement n. */ 
  } 
}
Consider the function increment_ints(), defined above. Despite its significant inline commentary, it contains an error. Which one of the following correctly assesses it?
Choice 1
*p++ causes p to be incremented before the dereference is performed, because both operators have equal precedence and are right associative.
Choice 2
An array is a nonmodifiable lvalue, so p cannot be incremented directly. A navigation pointer should be used in conjunction with p.
Choice 3
*p++ causes p to be incremented before the dereference is performed, because the autoincrement operator has higher precedence than the indirection operator.
Choice 4
The condition of a while loop must be a Boolean expression. The condition should be n != 0.
Choice 5
An array cannot be initialized to a variable size. The subscript n should be removed from the definition of the parameter p.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

/*question number 65*/
How is a variable accessed from another file?
Choice 1
The global variable is referenced via the extern specifier.[Ans]
Choice 2
The global variable is referenced via the auto specifier.
Choice 3
The global variable is referenced via the global specifier.
Choice 4
The global variable is referenced via the pointer specifier.
Choice 5
The global variable is referenced via the ext specifier.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

/*question number 66*/
When applied to a variable, what does the unary "&" operator yield?
Choice 1
The variable's value
Choice 2
The variable's binary form
Choice 3
The variable's address [Ans]
Choice 4
The variable's format
Choice 5
The variable's right value
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

/*question number 67*/
Code:
/* sys/cdef.h */ 
#if     defined(__STDC__) || defined(__cplusplus) 
#define __P(protos)   protos 
#else 
#define __P(protos)   () 
#endif 
/* stdio.h */ 
#include <sys/cdefs.h> 
div_t div __P((int, int));
The code above comes from header files for the FreeBSD implementation of the C library. What is the primary purpose of the __P() macro?
Choice 1
The __P() macro has no function, and merely obfuscates library function declarations. It should be removed from further releases of the C library.
Choice 2
The __P() macro provides forward compatibility for C++ compilers, which do not recognize Standard C prototypes.
Choice 3
Identifiers that begin with two underscores are reserved for C library implementations. It is impossible to determine the purpose of the macro from the context given.
Choice 4
The __P() macro provides backward compatibility for K&R C compilers, which do not recognize Standard C prototypes.
Choice 5
The __P() macro serves primarily to differentiate library functions from application-specific functions.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

/*question number 68*/
Which one of the following is NOT a valid identifier?
Choice 1
__ident
Choice 2
auto [Ans]
Choice 3
bigNumber
Choice 4
g42277
Choice 5
peaceful_in_space
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

/*question number 69*/
/* Read an arbitrarily long string. */
Code:
int read_long_string (const char ** const buf) { 
  char * p = NULL; 
  const char * fwd = NULL; 
  size_t len = 0; 
  assert(buf); 
  do
  { 
   p = realloc(p, len += 256); 
   if (!p) 
    return 0; 
   if (!fwd) 
    fwd = p; 
   else 
    fwd = strchr(p, '\0'); 
  } while (fgets(fwd, 256, stdin)); 
  *buf = p; 
  return 1; 
}
The function read_long_string(), defined above, contains an error that may be particularly visible under heavy stress. Which one of the following describes it?
Choice 1
The write to *buf is blocked by the const qualifications applied to its type.
Choice 2
If the null pointer for char is not zero-valued on the host machine, the implicit comparisons to zero (0) may introduce undesired behavior. Moreover, even if successful, it introduces machine-dependent behavior and harms portability.
Choice 3
The symbol stdin may not be defined on some ANCI C compliant systems.
Choice 4
The else causes fwd to contain an errant address.
Choice 5
If the call to realloc() fails during any iteration but the first, all memory previously allocated by the loop is leaked.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

/*question number 70*/
Code:
FILE *f = fopen( fileName, "r" ); 
readData( f ); 
if( ???? ) 
{ 
 puts( "End of file was reached" ); 
}
Which one of the following can replace the ???? in the code above to determine if the end of a file has been reached?
Choice 1
f == EOF[Ans]
Choice 2
feof( f )
Choice 3
eof( f )
Choice 4
f == NULL
Choice 5
!f
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

/*question number 71*/
Global variables that are declared static are ____________.
Which one of the following correctly completes the sentence above?
Choice 1
Deprecated by Standard C
Choice 2
Internal to the current translation unit
Choice 3
Visible to all translation units
Choice 4
Read-only subsequent to initialization
Choice 5
Allocated on the heap[Ans]
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

/*question number 72*/
/* Read a double value from fp. */
Code:
double read_double (FILE * fp) { 
  double d; 
  assert(fp != NULL); 
  fscanf(fp, " %lf", d); 
  return d; 
}
The code above contains a common error. Which one of the following describes it?
Choice 1
fscanf() will fail to match floating-point numbers not preceded by whitespace.
Choice 2
The format specifier %lf indicates that the corresponding argument should be long double rather than double.
Choice 3
The call to fscanf() requires a pointer as its last argument.
Choice 4
The format specifier %lf is recognized by fprintf() but not by fscanf().
Choice 5
d must be initialized prior to usage.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

/*question number 73*/
Which one of the following is NOT a valid C identifier?
Choice 1
___S
Choice 2
1___ [Ans]
Choice 3
___1
Choice 4
___
Choice 5
S___
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

/*question number 74*/
According to Standard C, what is the type of an unsuffixed floating-point literal, such as 123.45?
Choice 1
long double
Choice 2
Unspecified
Choice 3
float[Ans]
Choice 4
double
Choice 5
signed float
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

/*question number 75*/
Which one of the following is true for identifiers that begin with an underscore?
Choice 1
They are generally treated differently by preprocessors and compilers from other identifiers.
Choice 2
They are case-insensitive.
Choice 3
They are reserved for usage by standards committees, system implementers, and compiler engineers.
Choice 4
Applications programmers are encouraged to employ them in their own code in order to mark certain symbols for internal usage. Choice 5
They are deprecated by Standard C and are permitted only for backward compatibility with older C libraries.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

/*question number 76*/
Which one of the following is valid for opening a read-only ASCII file? Choice 1
fileOpen (filenm, "r");
Choice 2
fileOpen (filenm, "ra");
Choice 3
fileOpen (filenm, "read");
Choice 4
fopen (filenm, "read");
Choice 5
fopen (filenm, "r");[Ans]
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

/*question number 77*/
f = fopen( filename, "r" );
Referring to the code above, what is the proper definition for the variable f?
Choice 1
FILE f;
Choice 2
FILE *f;[Ans]
Choice 3
int f;
Choice 4
struct FILE f;
Choice 5
char *f;
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

/*question number 78*/
If there is a need to see output as soon as possible, what function will force the output from the buffer into the output stream?
Choice 1
flush()
Choice 2
output()
Choice 3
fflush()
Choice 4
dump()
Choice 5
write()
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

/*question number 79*/
short int x; /* assume x is 16 bits in size */
What is the maximum number that can be printed using printf("%d\n", x), assuming that x is initialized as shown above?
Choice 1
127
Choice 2
128
Choice 3
255
Choice 4
32,767 [Ans]
Choice 5
65,536
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

/*question number 80*/
Code:
void crash (void) 
{ 
 printf("got here"); 
 *((char *) 0) = 0; 
}
The function crash(), defined above, triggers a fault in the memory management hardware for many architectures. Which one of the following explains why "got here" may NOT be printed before the crash?
Choice 1
The C standard says that dereferencing a null pointer causes undefined behavior. This may explain why printf() apparently fails.
Choice 2
If the standard output stream is buffered, the library buffers may not be flushed before the crash occurs.
Choice 3
printf() always buffers output until a newline character appears in the buffer. Since no newline was present in the format string, nothing is printed.
Choice 4
There is insufficient information to determine why the output fails to appear. A broader context is required.
Choice 5
printf() expects more than a single argument. Since only one argument is given, the crash may actually occur inside printf(), which explains why the string is not printed. puts() should be used instead.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

/*question number 81*/
Code:
char * dwarves [] = { 
  "Sleepy", 
  "Dopey" "Doc", 
  "Happy", 
  "Grumpy" "Sneezy", 
  "Bashful", 
};
How many elements does the array dwarves (declared above) contain? Assume the C compiler employed strictly complies with the requirements of Standard C.
Choice 1
4
Choice 2
5[Ans]
Choice 3
6
Choice 4
7
Choice 5
8
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

/*question number 82*/
Which one of the following can be used to test arrays of primitive quantities for strict equality under Standard C?
Choice 1
qsort()
Choice 2
bcmp()
Choice 3
memcmp()
Choice 4
strxfrm()
Choice 5
bsearch()
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

/*question number 83*/
Code:
int debug (const char * fmt, ...) { 
  extern FILE * logfile; 
  va_list args; 
  assert(fmt); 
  args = va_arg(fmt, va_list); 
  return vfprintf(logfile, fmt, args); 
}
The function debug(), defined above, contains an error. Which one of the following describes it?
Choice 1
The ellipsis is a throwback from K&R C. In accordance with Standard C, the declaration of args should be moved into the parameter list, and the K&R C macro va_arg() should be deleted from the code.
Choice 2
vfprintf() does not conform to ISO 9899: 1990, and may not be portable.
Choice 3
Library routines that accept argument lists cause a fault on receipt of an empty list. The argument list must be validated with va_null() before invoking vfprintf().
Choice 4
The argument list args has been improperly initialized.
Choice 5
Variadic functions are discontinued by Standard C; they are legacy constructs from K&R C, and no longer compile under modern compilers.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

/*question number 84*/
Code:
char *buffer = "0123456789"; 
char *ptr = buffer; 
ptr += 5; 
printf( "%s\n", ptr ); 
printf( "%s\n", buffer );
What will be printed when the sample code above is executed?
Choice 1
0123456789
56789
Choice 2
5123456789
5123456789
Choice 3
56789
56789
Choice 4
0123456789
0123456789
Choice 5
56789
0123456789 [Ans]
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

/*question number 85*/
/* Get the rightmost path element of a Unix path. */
Code:
char * get_rightmost (const char * d)
{ 
 char rightmost [MAXPATHLEN]; 
 const char * p = d; 
 assert(d != NULL); 
 while (*d != '\0')
 { 
  if (*d == '/') 
   p = (*(d + 1) != '\0') ? d + 1 : p; 
  d++; 
 } 
 memset(rightmost, 0, sizeof(rightmost)); 
 memcpy(rightmost, p, strlen(p) + 1); 
 return rightmost; 
}
The function get_rightmost(), defined above, contains an error. Which one of the following describes it?
Choice 1
The calls to memset() and memcpy() illegally perform a pointer conversion on rightmost without an appropriate cast.
Choice 2
The code does not correctly handle the situation where a directory separator '/' is the final character.
Choice 3
The if condition contains an incorrectly terminated character literal.
Choice 4
memcpy() cannot be used safely to copy string data.
Choice 5
The return value of get_rightmost() will be invalid in the caller's context.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

/*question number 86*/
What number is equivalent to -4e3?
Choice 1
-4000 [Ans]
Choice 2
-400
Choice 3
-40
Choice 4
.004
Choice 5
.0004
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

/*question number 87*/
Code:
void freeList( struct node *n ) 
{ 
 while( n ) 
 { 
  ???? 
 } 
}
Which one of the following can replace the ???? for the function above to release the memory allocated to a linked list?
Choice 1
n = n->next;
free( n );
Choice 2
struct node m = n;
n = n->next;
free( m );
Choice 3
struct node m = n;
free( n );
n = m->next;
Choice 4
free( n );
n = n->next;
Choice 5
struct node m = n;
free( m );
n = n->next;
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

/*question number 88*/
How does variable definition differ from variable declaration?
Choice 1
Definition allocates storage for a variable, but declaration only informs the compiler as to the variable's type.
Choice 2
Declaration allocates storage for a variable, but definition only informs the compiler as to the variable's type.
Choice 3
Variables may be defined many times, but may be declared only once.[Ans]
Choice 4
Variable definition must precede variable declaration.
Choice 5
There is no difference in C between variable declaration and variable definition.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

/*question number 89*/
Code:
int x[] = {1, 2, 3, 4, 5}; 
int u; 
int *ptr = x; 
???? 
for( u = 0; u < 5; u++ )
{
 printf("%d-", x[u]); 
}
printf( "\n" );
Which one of the following statements could replace the ???? in the code above to cause the string 1-2-3-10-5- to be printed when the code is executed?
Choice 1
*ptr + 3 = 10;
Choice 2
*ptr[ 3 ] = 10;
Choice 3
*(ptr + 3) = 10;[Ans]
Choice 4
(*ptr)[ 3 ] = 10;
Choice 5
*(ptr[ 3 ]) = 10;
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

/*question number 90*/
Code:
/*sum_array() has been ported from FORTRAN. No * logical changes have been made*/
double sum_array(double d[],int n)
{
 register int i;
 double total=0;
 assert(d!=NULL);
 for(i=l;i<=n;i++)
  total+=d[i];
 return total;
}
The function sum_array(), defined above, contains an error. Which one of the following accurately describes it?
Choice 1
The range of the loop does not match the bounds of the array d.
Choice 2
The loop processes the incorrect number of elements.
Choice 3
total is initialized with an integer literal. The two are not compatible in an assignment.
Choice 4
The code above fails to compile if there are no registers available for i.
Choice 5
The formal parameter d should be declared as double * d to allow dynamically allocated arrays as arguments.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

/*question number 91*/
Code:
#include <stdio.h> 
void func() 
{ 
   int x = 0; 
   static int y = 0; 
   x++; y++; 
   printf( "%d -- %d\n", x, y ); 
} 

int main() 
{ 
   func(); 
   func(); 
   return 0; 
}
What will the code above print when it is executed?
Choice 1
1 -- 1
1 -- 1
Choice 2
1 -- 1
2 -- 1
Choice 3
1 -- 1
2 -- 2
Choice 4
1 -- 0
1 -- 0
Choice 5
1 -- 1
1 -- 2 [Ans]
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

/*question number 92*/ $$No other seems that sound$$
Code:
int fibonacci (int n)
{ 
 switch (n)
 { 
  default: 
      return (fibonacci(n - 1) + fibonacci(n - 2)); 
  case 1: 
  case 2: 
 } 
  return 1; 
}
The function above has a flaw that may result in a serious error during some invocations. Which one of the following describes the deficiency illustrated above?
Choice 1
For some values of n, the environment will almost certainly exhaust its stack space before the calculation completes.
[Ans]
Choice 2
An error in the algorithm causes unbounded recursion for all values of n.
Choice 3
A break statement should be inserted after each case. Fall-through is not desirable here.
Choice 4
The fibonacci() function includes calls to itself. This is not directly supported by Standard C due to its unreliability.
Choice 5
Since the default case is given first, it will be executed before any case matching n.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

/*question number 93*/
When applied to a variable, what does the unary "&" operator yield?
Choice 1
The variable's address [Ans]
Choice 2
The variable's right value
Choice 3
The variable's binary form
Choice 4
The variable's value
Choice 5
The variable's format
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

/*question number 94*/
short int x; /* assume x is 16 bits in size */
What is the maximum number that can be printed using printf("%d\n", x), assuming that x is initialized as shown above?
Choice 1
127
Choice 2
128
Choice 3
255
Choice 4
32,767[Ans]
Choice 5
65,536
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

/*question number 95*/
int x = 011 | 0x10;
What value will x contain in the sample code above?
Choice 1
3
Choice 2
13
Choice 3
19
Choice 4
25
Choice 5
27
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

/*question number 96*/
Which one of the following calls will open the file test.txt for reading by fgetc?
Choice 1
fopen( "test.txt", "r" );
Choice 2
read( "test.txt" )
Choice 3
fileopen( "test.txt", "r" );
Choice 4
fread( "test.txt" )
Choice 5
freopen( "test.txt" )
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

/*question number 97*/
Code:
int m = -14; 
int n = 6; 
int o; 
o = m % ++n; 
n += m++ - o; 
m <<= (o ^ n) & 3;
Assuming two's-complement arithmetic, which one of the following correctly represents the values of m, n, and o after the execution of the code above?
Choice 1
m = -26, n = -7, o = 0
Choice 2
m = -52, n = -4, o = -2
Choice 3
m = -26, n = -5, o = -2
Choice 4
m = -104, n = -7, o = 0
Choice 5
m = -52, n = -6, o = 0
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

/*question number 98*/
How do printf()'s format specifiers %e and %f differ in their treatment of floating-point numbers?
Choice 1
%e displays an argument of type double with trailing zeros; %f never displays trailing zeros.
Choice 2
%e displays a double in engineering notation if the number is very small or very large. Otherwise, it behaves like %f and displays the number in decimal notation.
Choice 3
%e always displays an argument of type double in engineering notation; %f always displays an argument of type double in decimal notation. [Ans]
Choice 4
%e expects a corresponding argument of type double; %f expects a corresponding argument of type float.
Choice 5
%e and %f both expect a corresponding argument of type double and format it identically. %e is left over from K&R C; Standard C prefers %f for new code.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

/*question number 99*/ $$Except 1 all choices are O.K.$$
c = getchar();
What is the proper declaration for the variable c in the code above?
Choice 1
char *c;
Choice 2
unsigned int c;
Choice 3
int c;
Choice 4
unsigned char c;
Choice 5
char c;[Ans]
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

/*question number 100*/
Which one of the following will define a function that CANNOT be called from another source file?
Choice 1
void function() { ... }
Choice 2
extern void function() { ... }
Choice 3
const void function() { ... }
Choice 4
private void function() { ... }
Choice 5
static void function() { ... }
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

 http://www.go4expert.com