What Is Difference Between Malloc and Calloc?
What Is Difference Between Malloc and Calloc?
1. malloc takes only the size of the memory block to be allocated as input parameter.
2. malloc allocates memory as a single contiguous block.
3. if a single contiguous block cannot be allocated then malloc would fail.
1. calloc takes two parameters: the number of memory blocks and the size of each block of memory
2. calloc allocates memory which may/may not be contiguous.
3. all the memory blocks are initialized to 0.
4. it follows from point 2 that calloc will not fail if memory can beallocated in non-contiguous blocks
when a single contiguous blockcannot be allocated.
malloc is dynamic memory allocation it allocates the memory and initialize garbage value.
Enums are group of symbolic constant each having some integer value.
enum(PASS_MARK=60,MERIT_MARK=70)
defines two symbolic constant PASS_MARK and MERIT_MARK as 60 and 70,- it could be
done with #define as well.
However without specific values ,- the values are assigned automatically ,- starting with
0 for the first element and 1 for the second, 3 for the second etc.
In case if we state a number for the first element then it will increment the value of each
consecutive elemts with '1'.
enum(MON=1,TUE,WED,THU,FRI,SAT,SUN);
Answer
A union is a way of providing an alternate way of describing the same memory area. In this way, you
could have a struct that contains a union, so that the "static", or similar portion of the data is
described first, and the portion that changes is described by the union. The idea of a union could be
handled in a different way by having 2 different structs defined, and making a pointer to each kind of
struct. The pointer to struct "a" could be assigned to the value of a buffer, and the pointer to struct
"b" could be assigned to the same buffer, but now a->somefield and b->someotherfield are both
located in the same buffer. That is the idea behind a union. It gives different ways to break down the
same buffer area.
Answer:
The difference between structure and union in c are: 1. union allocates the memory equal to the
maximum memory required by the member of the union but structure allocates the memory equal to
the total memory required by the members. 2. In union, one block is used by all the member of the
union but in case of structure, each member have their own memory space
There is frequent rwquirement while interacting with hardware to access access a byte or group of
bytes simultaneously and sometimes each byte individually. Usually union is the answer.
=======Difference With example***** Lets say a structure containing an int,char and float is
created and a union containing int char float are declared. struct TT{ int a; float b; char c; } Union
UU{ int a; float b; char c; }
sizeof TT(struct) would be >9 bytes (compiler dependent-if int,float, char are taken as 4,4,1)
sizeof UU(Union) would be 4 bytes as supposed from above.If a variable in double exists in union then
the size of union and struct would be 8 bytes and cumulative size of all variables in struct.
Detailed Example:
struct foo
{
char c;
long l;
char *p;
};
union bar
{
char c;
long l;
char *p;
};
A union bar contains only one of the elements c, l, and p at any given
time. Each element is stored in the same memory location (well, they all
start at the same memory location), and you can only refer to the element
which was last stored. (ie: after "barptr->c = 2;" you cannot reference
any of the other elements, such as "barptr->p" without invoking undefined
behavior.)
==========
#include
struct foo
{
char c;
long l;
char *p;
};
union bar
{
char c;
long l;
char *p;
};
myfoo.c = 1;
myfoo.l = 2L;
myfoo.p = "This is myfoo";
mybar.c = 1;
mybar.l = 2L;
mybar.p = "This is mybar";
return 0;
}
==========
On my system, I get:
==========
I want to thank you for your reply. However, I need some clarification.
2. I am somewhat familiar with the method using division. For example, gcd for (84, 18): "Divide
84 by 18 to get a quotient of 4 and a remainder of 12. Then divide 18 by 12 to get a quotient of 1
and a remainder of 6. Then divide 12 by 6 to get a remainder of 0, which means that 6 is the gcd."
I am curious to know whether or not this method could be used with more than two numbers, 4, 8,
and 16.
"argc" stands for "argument count". It is the number of elements in "argv", "argument
vector". (While "vector" and "array" mean different things in java, traditionally they
are synonyms.)
While "argc" and "argv" are theoretically arbitrary parameter names, the use of the
names "argc" and "argv" is so standard that you should never use any other name.
Since a string can be passed around as a value of type pointer-to-char, argv will be an
array of pointers-to-char. And when argv is passed to main() by the operating system,
it will decay into a pointer to its zeroth element, so the data will be of type pointer-to-
pointer-to-char.
The array is one element larger than you might think. The program name itself is
argv[0], so the first command-line argument is argv[1], and so on, and argc reflects
the total number of items in the argv array including this argv[0]. Often we ignore
argv[0] altogether.
Example 1: Write a program which first checks that argc is at least 2, then prints the
value of argv[1] (using %s). A session with this program might look like this, where
'%' is your shell prompt:
% ./a.out hello, world
hello,
%
Since "world" is argv[2], it didn't print that part. The shell (command interpreter)
divides up the arguments based on spaces.
Solution:
#include <stdio.h>
Mentioning the array name in C or C++ gives the base address in all contexts except one.
Syntactically, the compiler treats the array name as a pointer to the first element. You can
reference elements using array syntax, a[n], or using pointer syntax, *(a+n), and you can even
mix the usages within an expression. When you pass an array name as a function argument, you
are passing the "value of the pointer", which means that you are implicitly passing the array by
reference, even though all parameters in functions are "call by value".
There is, however, one very important distinction. While an array name is referentially the same
as a pointer, it is not a pointer in that it does not occupy program referential space in the process.
This means that, while you can change the value of a pointer, and thus the address to which it
points, you can not change the value of an array name. This distinction is what we call R-Value
(array or pointer) as opposed to L-Value (pointer only), i.e. can the object appear on the left sign
of an assignment operator.
9. What is a NULL Macro? What is the difference between a NULL Pointer and a NULL
Macro?
Null macro is defined in stdio.h and stddef.h.It is used to represent a null pointer in your code.
Null pointer is a pointer which has 0 or NULL value stored and points to nowhwere still it
points to 0x00 i.e. the first memory location of the OS
Null pointer != Uninitialized pointer because an uninitialised pointer can point anywhere in
the memory location ...but a NULL pointer surely points to no where(but still behind the scene
we can say that it only points to 0x00). Never we can retrive a Null pointer location using
th"&" operator..neither will malloc/calloc return NULL IF THERE IS SPACE IN THE
MEMORY. NULL pointer is unique !!
10. What is a NULL Pointer? Whether it is same as an uninitialized pointer?
NULL pointer is pointer which is not pointing to anything in the memory. NULL is defined as
(void*)0.
Uninitialised pointer is pointing to some memory location but the pointer values are not
assigned.
Mallocreturns the memory address, but the contents of the pointer are junk values.
HTTP modules and HTTP handlers are an integral part of the ASP.NET architecture. While a request is being
processed, each request is processed by multiple HTTP modules (for example, the authentication module
and the session module) and is then processed by a single HTTP handler. After the handler has processed
the request, the request flows back through the HTTP modules.
• HTTP Modules
o Available Events
o Configuring HTTP Modules
o Creating HTTP Modules
• HTTP Handlers
o Configuring HTTP Handlers
o Creating HTTP Handlers
HTTP Modules
Modules are called before and after the handler executes. Modules enable developers to intercept,
participate in, or modify each individual request. Modules implement theIHttpModule interface, which is
located in the System.Web namespace.
Available Events
An HttpApplication class provides a number of events with which modules can synchronize. The following
events are available for modules to synchronize with on each request. These events are listed in sequential
order:
• BeginRequest: Request has been started. If you need to do something at the beginning of a
request (for example, display advertisement banners at the top of each page), synchronize this
event.
• AuthenticateRequest: If you want to plug in your own custom authentication scheme (for
example, look up a user against a database to validate the password), build a module that
synchronizes this event and authenticates the user how you want to.
• AuthorizeRequest: This event is used internally to implement authorization mechanisms (for
example, to store your access control lists (ACLs) in a database rather than in the file system).
Although you can override this event, there are not many good reasons to do so.
• ResolveRequestCache: This event determines if a page can be served from the Output cache. If
you want to write your own caching module (for example, build a file-based cache rather than a
memory cache), synchronize this event to determine whether to serve the page from the cache.
• AcquireRequestState: Session state is retrieved from the state store. If you want to build your
own state management module, synchronize this event to grab the Session state from your state
store.
• PreRequestHandlerExecute: This event occurs before the HTTP handler is executed.
• PostRequestHandlerExecute: This event occurs after the HTTP handler is executed.
• ReleaseRequestState: Session state is stored back in the state store. If you are building a custom
session state module, you must store your state back in your state store.
• UpdateRequestCache: This event writes output back to the Output cache. If you are building a
custom cache module, you write the output back to your cache.
• EndRequest: Request has been completed. You may want to build a debugging module that
gathers information throughout the request and then writes the information to the page.
The following events are available for modules to synchronize with for each request transmission. The order
of these events is non-deterministic.
• PreSendRequestHeaders: This event occurs before the headers are sent. If you want to add
additional headers, you can synchronize this event from a custom module.
• PreSendRequestContent: This event occurs when the Response.Flush method is called. If you
want to add additional content, you can synchronize this event from a custom module.
Error: This event occurs when an unhandled exception occurs. If you want to write a custom error
HTTP Handlers
Handlers are used to process individual endpoint requests. Handlers enable the ASP.NET framework to
process individual HTTP URLs or groups of URL extensions within an application. Unlike modules, only one
handler is used to process a request. All handlers implement theIHttpHandler interface, which is located in
the System.Web namespace. Handlers are somewhat analogous to Internet Server Application
Programming Interface (ISAPI) extensions.
<httpHandlers>
<add verb="[verb list]" path="[path/wildcard]" type="[COM+ Class], [Assembly]"
validate="[true/false]" />
<remove verb="[verb list]" path="[path/wildcard]" />
<clear />
</httpHandlers>
void ProcessRequest(HttpContext);
bool IsReusable {get;}
NOTE: If session state is required in your HTTP handler, you also need to implement
theIRequiresSessionState interface. For additional information about creating HTTP handlers, click the
article numbers below to view the articles in the Microsoft Knowledge Base:
308001 HOW TO: Create an ASP.NET HTTP Handler by Using Visual C# .NET
12. What is the difference between transaction database and data warehouse databases?
1. Transaction Database is Relational Database with the normalised table, whereas DataWarehouse is
with denormalised Table.
2. Transaction Database is highly volatile... Designed to maintain transaction of the business Where
DataWarehouse is non volatile.. with periodic updates.
The following is a list of the kinds of applications that can generate Transact-SQL:
• General office productivity applications.
• Applications that use a graphical user interface (GUI) to let users select the tables and
columns from which they want to see data.
• Applications that use general language sentences to determine what data a user wants to
see.
• Line of business applications that store their data in SQL Server databases. These applications
can include both applications written by vendors and applications written in-house.
• Transact-SQL scripts that are run by using utilities such as sqlcmd.
• Applications created by using development systems such as Microsoft Visual C++, Microsoft
Visual Basic, or Microsoft Visual J++ that use database APIs such as ADO, OLE DB, and ODBC.
• Web pages that extract data from SQL Server databases.
• Distributed database systems from which data from SQL Server is replicated to various
databases, or distributed queries are executed.
• Data warehouses in which data is extracted from online transaction processing (OLTP) systems
and summarized for decision-support analysis.
Also in short,
T-SQL (Transact-SQL) is a set of programming extensions from Sybase and Microsoft that add several
features to the Structured Query Language (SQL) including transaction control, exception and error
handling, row processing, and declared variables. Microsoft's SQL server and Sybase's SQL server
support T-SQL statements.
he simplest and safest way to prevent lock escalation is to keep transactions short and to reduce the lock
footprint of expensive queries so that the lock escalation thresholds are not exceeded. There are several
ways to obtain this goal, many of which are listed:
• Break up large batch operations into several smaller operations.
17. What is bit datatype and what,s the information that can be stored inside a bit column?
24. What is bit data type and what's the information that can be stored inside a bit column? Bit data type
is used to store Boolean information like 1 or 0 (true or false). Until SQL Server 6.5 bit data type could
hold either a 1 or 0 and there was no support for NULL. But from SQL Server 7.0 onwards, bit data type
can represent a third state, which is NULL.
18. What is a transaction and what are ACID properties? Explain the architecture of SQL Server
A transaction is a logical unit of work in which, all the steps must be performed or none. ACID
stands for Atomicity, Consistency, Isolation, Durability. These are the properties of a transaction.
For more information and explanation of these properties, see SQL Server books online or any
RDBMS fundamentals text book
This tutorial covers the different types of OLAP models like Relational Online Analytical Processing
mode( ROLAP), Multidimensional Online Analytical processing mode(MOLAP) and Hybrid Online
Analytical Processing mode or HOLAP.
Sponsored Links
Cubes in a data warehouse are stored in three different modes. A relational storage model is called
Relational Online Analytical Processing mode or ROLAP, while a MultidimensionalOnline Analytical
processing mode is called MOLAP. When dimensions are stored in a combination of the two modes
then it is known as Hybrid Online Analytical Processing mode or HOLAP.
MOLAP
This is the traditional mode in OLAP analysis. In MOLAP data is stored in form
of multidimensionalcubes and not in relational databases. The advantages of this mode is
that it provides excellent query performance and the cubes are built for fast data retrieval.
All calculations are pre-generated when the cube is created and can be easily applied while
querying data. The disadvantages of this model are that it can handle only a limited amount
of data. Since allcalculations have been pre-built when the cube was created, the cube
cannot be derived from a large volume of data. This deficiency can be bypassed by including
only summary level calculations while constructing the cube. This model also requires huge
additional investment as cube technology is proprietary and the knowledge base may not
exist in the organization.
ROLAP
The underlying data in this model is stored in relational databases. Since the data is stored
in relational databases this model gives the appearance of traditional OLAP’s slicing and
dicing functionality. The advantages of this model is it can handle a large amount of data
and can leverage all the functionalities of the relational database. The disadvantages are
that the performance is slow and each ROLAP report is an SQL query with all the limitations
of the genre. It is also limited by SQL functionalities. ROLAP vendors have tried to mitigate
this problem by building into the tool out-of-the-box complex functions as well as providing
the users with an ability to define their own functions.
HOLAP
HOLAP technology tries to combine the strengths of the above two models. For summary
type information HOLAP leverages cube technology and for drilling down into details it uses
the ROLAP model.
The type of storage medium impacts on cube processing time, cube storage and cube
browsing speed. Some of the factors that affect MOLAP storage are:
Cube browsing is the fastest when using MOLAP. This is so even in cases where no
aggregations have been done. The data is stored in a compressed multidimensional format
and can be accessed quickly than in the relational database. Browsing is very slow in ROLAP
about the same in HOLAP. Processing time is slower in ROLAP, especially at higher levels of
aggregation.
MOLAP storage takes up more space than HOLAP as data is copied and at very low levels of
aggregation it takes up more room than ROLAP. ROLAP takes almost no storage space as
data is not duplicated. However ROALP aggregations take up more space than MOLAP or
HOLAP aggregations.
All data is stored in the cube in MOLAP and data can be viewed even when the original data
source is not available. In ROLAP data cannot be viewed unless connected to the data
source.
MOLAP can handle very limited data only as all data is stored in the cube.
20. What are the ODBC drivers that are available for PostgreSQL?
There are five aggregate system functions they are viz. Sum Min Max Avg Count. They all have their
own purpose Decomposition: Selecting all data without
any grouping and aggregate functions is called Decomposition. The data is selected as it is present in
the table.
Generalization: while generalization seems to be simplification of data i.e. to bring the data from Un-
normalized form to normalized form.
Every sub-group will be able to inherit the associates, and this means the developer only
needs to create the code for them one time. The traits that are inherited by the sub-group
can be changed. For example, the Persian cat class may choose to make the Colorfur white
for their default color. In contrast, another cat breed may choose a different Colorfur trait.
It is also possible for the sub-group to add new associates. If a specific cat Class sub-group
wants to set a default eye color, this can be inherited as well. Some object oriented
programming languages may also allow a class to inherit traits from multiple ancestors, and
this is called multiple inheritance. Some programs may not allow this.
The next concept that you will want to be familiar with is called
"abstraction." Abstraction can be defined as the process in which an application will ignore
the characteristics of a sub-group and work on a general level when it is needed. As an
example, Betsy the cat may be treated as a cat when it is necessary, but she may also be
processed as a Felidae, which is a superclass of cat family. Polymorphism is an important
concept of object oriented programming that you will want to become familiar. It can be
defined as a behavior which is dependent on the class to which it is connected. As an
example, if a Cat is sent a command to speak, this may cause it to purr, while a dog will
bark, or a lion may roar.
Anyone who is interested in object oriented programming will also need to know
encapsulation. Encapsulation will allow a class to hide information from objects that may
use the code. For example, the Cat class will have a purr() method. A code will be written
which will explain how the cat purrs. Despite this, it is not necessary for Betsy the cat to
know how she purrs. Encapsulation makes it easier for the developer to change the code
without having to change the code for Betsy. When the structure of class is hidden, it is
harder for it to be used in the wrong way.
Encapsulation will basically state which class is allowed to use the members of a certain
object. This concept makes it easier for programmers to deal with or avoid errors when
developing a program. The members within OOP can be categorized as being protected,
public, or private. The last concept that you will want to become familiar with is called an
event. An event can simply be defined as anything that happens to an object. Generally, an
event is something that will cause the object to react with a method. Another term that
advanced programmers may run into is called multiple inheritance. It is a situation where a
class is able to inherit traits from a number of different superclasses.
A multiple inheritance can create a number of perplexing situations. Because of this, there is
debate in the programming community about whether it is beneficial or risky. One example
of a program which deals with multiple inheritances is Java.
dbv
The Database Verify utility (dbv) provides a mechanism to
validate the structure of Oracle data files at the operating
system level. It should be used on a regular basis to
inspect data files for signs of corruption.
try{
}
catch(SQLException se)
{
se.printStackTrace();
}
catch(Exception ee)
{
ee.printStackTrace();
}
To insert images into a database, the database must support images. Images are stored in binary in a
table cell. The data type for the cell is a binary large object (BLOB), which is a new SQL type in SQL3
for storing binary data. Another new SQL3 type is character large object (CLOB), for storing a large text
in the character format. JDBC 2 introduced the interfaces java.sql.Blob and java.sql.Clob to support
mapping for these new SQL types. JBDC 2 also added new methods, such as getBlob, setBinaryStream,
getClob, setBlob, and setClob, in the interfaces ResultSet, PreparedStatement, and CallableStatement,
to access SQL BLOB and CLOB values.
To store an image in a cell in a table, the corresponding column for the cell must be of the BLOB type.
For example, the following SQL statement creates a table whose type for the flag column is BLOB:
To insert a record with images to a table, define a prepared statement like this one:
Images are usually stored in files. You may first get an instance of InputStream for an image file and
then use the setBinaryStream method to associate the input stream with cell in the table, as follows:
To retrieve an image from a table, use the getBlob method, as shown here:
SQl Server is a server based database. Access is used as local database.Access is used for small
desktop size databases used by less then 5 users at the same time. It has a front end gui system to
design applications quickly. SQL Server is a more robust system and is able to handle large amounts
of users as well as data sizes. There is no front end gui system so it will require other development
tools (Visual Studios, .NET, VB, C++, ect.).
Access is intended more for end-user(s), as it's an all-inclusive package. It's mainly for one use at a
time, but it does support multiple users, albeit in a clunky roundabout way. Remember, it is a tool in
MS Office.
MS SQL Server is an actual SQL database. It's designed to sit on a server an act as the database
for whatever front-end you wish to put on it. It's mainly for multiple users and intended to be
centralized.
MS Access is actually a combination of a rapid development UI tool and file system based relational
database (JET).
MS SQL Server is a Client-server relational database system, with no UI development tools built in.
29. How can I get the heading of a report to appear on every page?
Sql reporting service,crystalreports.
The Report Header is only displayed once, at the very beginning of a report.
There is a page header section in the report that you can use when you want that to repeat
on every page. You can turn off repeat on first and last page for the page header using the 2
properties that the page header supports. There is no report header in RDL.
If you only want the header to show on the first page, you cannot use the page header. To
get that affect, you can place a rectangle at the top of your report body and put any
information you want in it. The rectangle will only show on the first page and can act as a
page header for you.
We'll need to open the database using a special procedure to ensure there are no other users. The first
step is to click the Microsoft Office button, as shown in the image above.
Note that this feature is only available if you're using Microsoft Office Access 2007 and your database
is in ACCDB format.
Next, choose Open from the Office menu. Please read the next step before opening your database. We
need to open it in a special way to ensure that it's ready for encryption. This process is shown in the
image above.
Navigate to the database you'd like to encrypt and then click it once. Then, instead of just clicking the
Open button, click the downward arrow icon to the right of the button, as shown in the image above.
Choose "Open Exclusive" to open the database in exclusive mode.
From the Database Tools tab, double-click on the "Encrypt with Password" option, as shown in the
image above
Choose a strong password for your database and enter it in both the Password and Verify boxes in the
Set Database Password dialog box, as shown in the image above. Once you've done this, click OK.
That's all there is to it. After clicking OK, your database will be encrypted. (This may take a while
depending upon the size of your database). The next time you open your database, you'll be prompted
to enter the password before accessing it.
32. I am using the Switchboard Manager in MS Access. I am getting an error message "...
The Switchboard manager in MS Access offers only limited information on errors that occur within the
database. Execute the selection directly from the database window to get more detailed information on
the error.
client requirement.
Verification ensures that the application complies to
standards and processes. This answers the question " Did we
build the right system? "