Krify Articles
  Sign Up | Log In     Krify Home | Videos | Buzz | Free SMS | Matrimony | Answers | Web Hosting | Bulk SMS | Mail | News | Blogs


Music | Shopping | Forums | Freelance | Wall papers | Classifieds | Web director | Greetings | Bookmarks | Search | Games | Adman

Home Recent Articles Popular Articles Article of the day
Category list


Advertisements Ask Questions, Share Knowledge with Krify Answers
 
Posted by:  radhesh
 Article viewed:  2750  times



Questions and Answers in C
Is it better to use a macro or a function?

 

The answer depends on the situation you are writing code for. Macros have the distinct advantage of being more efficient (and faster) than functions, because their corresponding code is inserted directly into your source code at the point where the macro is called. There is no overhead involved in using a macro like there is in placing a call to a function. However, macros are generally small and cannot handle large, complex coding constructs. A function is more suited for this type of situation. Additionally,
macros are expanded inline, which means that the code is replicated for each occurrence of a macro. Your code therefore could be somewhat larger when you use macros than if you were to use functions.

Thus, the choice between using a macro and using a function is one of deciding between the tradeoff of faster program speed versus smaller program size. Generally, you should use macros to replace small, repeatable code sections, and you should use functions for larger coding tasks that might require several lines of code

 

 

What is the purpose of main( ) function?

The function main( ) invokes other functions within it. It is the first function to be called when the program starts execution.

Ř It is the starting function

Ř It returns an int value to the environment that called the program

Ř Recursive call is allowed for main( ) also.

Ř It is a user-defined function

Ř Program execution ends when the closing brace of the function main( ) is reached.

Ř It has two arguments 1)argument count and 2) argument vector (represents strings passed).

Ř Any user-defined name can also be used as parameters for main( ) instead of argc and argv

 

What is a pragma?

The #pragma preprocessor directive allows each compiler to implement compiler-specific features that can be turned on and off with the #pragma statement. For instance, your compiler might support a feature called loop optimization. This feature can be invoked as a command-line option or as a #pragma directive.

To implement this option using the #pragma directive, you would put the following line into your code:

#pragma loop_opt(on)

Conversely, you can turn off loop optimization by inserting the following line into your code:

#pragma loop_opt(off)
 

What is static memory allocation and dynamic
memory allocation?

Static memory allocation: The compiler allocates the required memory space for a declared variable.By using the address of operator,the reserved address is obtained and this address may be assigned to a pointer variable.Since most of the declared variable have static memory,this way of assigning pointer value to a pointer variable is known as static memory allocation. memory is assigned during compilation time.

Dynamic memory allocation: It uses functions such as malloc( ) or calloc( ) to get memory dynamically.If these functions are used to get memory dynamically and the values returned by these functions are assingned to pointer variables, such assignments are known as dynamic memory allocation.memory is assined during run time.

 

How are pointer variables initialized?

 

Pointer variable are initialized by one of the following two ways

Ř Static memory allocation

Ř Dynamic memory allocation

 

What is the difference between #include <file> and #include “file”?

 

When writing your C program, you can include files in two ways. The first way is to surround the file you
want to include with the angled brackets < and >. This method of inclusion tells the preprocessor to look for the file in the predefined default location. This predefined default location is often an INCLUDE environment variable that denotes the path to your include files. For instance, given the INCLUDE variable

INCLUDE=C:COMPILERINCLUDE;S:SOURCEHEADERS;

using the #include version of file inclusion, the compiler first checks the C:COMPILERINCLUDE
directory for the specified file. If the file is not found there, the compiler then checks the
S:SOURCEHEADERS directory. If the file is still not found, the preprocessor checks the current directory.

The second way to include files is to surround the file you want to include with double quotation marks. This method of inclusion tells the preprocessor to look for the file in the current directory first, then look for it in the predefined locations you have set up. Using the #include “file” version of file inclusion and applying it to the preceding example, the preprocessor first checks the current directory for the specified file. If the file is not found in the current directory, the C:COMPILERINCLUDE directory is searched. If the file is still not found, the preprocessor checks the S:SOURCEHEADERS directory.
The #include method of file inclusion is often used to include standard headers such as stdio.h or
stdlib.h. This is because these headers are rarely (if ever) modified, and they should always be read from your compiler’s standard include file directory.

The #include “file” method of file inclusion is often used to include nonstandard header files that you have created for use in your program. This is because these headers are often modified in the current directory, and you will want the preprocessor to use your newly modified version of the header rather than the older, unmodified version

Disclaimer: The above article is responsible of the individual who post, krify.com does not hold responsible for any kind of disinformation. If you discover one or more of the krify.com pages direct you to messages that harass, abuse, have obscene, unlawful, defamatory, libellous, hateful, or otherwise objectionable content; or have spam, please inform to krify.com and that will be deleted as soon as possible.

Other interesting Article in the Category Programming
  Write Your First Application in Win32 using Assembly Language
  APPLYING FORMULA IN A TABLE
  The First Cup of Java
  Dynamic-link library
  XML Parsing using PHP (Easy)
  Prevent mistypings to the String class
  Memory Management with PHP
  Take Command with AJAX
  Introduction to C++
  Event Handling and Interfaces in .NET

Write your Comment
Name:
Message:
 Verification code:    

Home Email to Friend
Google Pack

© Copyright - 2007 KRIFY SOFTWARE TECHNOLOGIES (P) LTD