Very Short Questions Spring 2016 || Programming Language

Very Short Questions Spring 2016

Very Short Questions Spring 2016

The answer to the Very Short Questions Spring 2016 are given below:

1.What are the purpose of & and * operators in pointer?

ANS- The ‘*’  operator is used to access pointed memory, and the & operator is used to get an address in memory.

2. Write the syntax of the switch statement.

ANS- switch(expression) {

case constant-expression :
statement(s);
break; /* optional */

case constant-expression :
statement(s);
break; /* optional */

/* you can have any number of case statements */
default : /* Optional */
statement(s);
}

3. Differentiate between malloc ( ) and calloc ( ) function.

ANS-

BASIS OF COMPARISON MALLOC() CALLOC()
No of blocks Assigns a single block of demanded memory. Assigns multiple blocks of the requested memory.
Syntax void *malloc(size_t size); void *calloc(size_t num, size_t size);

4. Why the function prototype is used?

ANS- The function prototypes are used to tell the compiler about the number of arguments and about the required datatypes of a function parameter, it also tells about the return type of the function. With this information, the compiler cross-checks the function signatures before calling it.

5. Is it necessary to include the header file at the beginning of any program? Why?

ANS- Yes, it is necessary to include the header file at the beginning of any program. C language has numerous libraries that include predefined functions to make programming easier. In C language, header files contain the set of predefined standard library functions. Your request to use a header file in your program by including it with the C preprocessing directive “#include”.

6. Define program and programming language.

ANS- A programming language is a computer language engineered to create a standard form of commands. These commands can be interpreted into a code understood by a machine. Programs are created through programming languages to control the behaviour and output of a machine through accurate algorithms, similar to the human communication process.

7. Define macro.

ANS- A macro in C programming language is a block or set of statements of program code that can be replaced by macro #define directive. As discussed above there are two types of macros.

8. Mention all the bitwise operators.

ANS-

Operator Meaning
& Bitwise AND operator
| Bitwise OR operator
^ Bitwise exclusive OR operator
~ Binary One’s Complement Operator is a unary operator
<< Left shift operator
>> Right shift operator

9. Write a four-string related function with proper syntax.

ANS- Following are some of the useful string handling functions supported by C.\

  • strlen()
  • strcpy()
  • strncpy()
  • strcat()

10. Where unions are used. Explain.

ANS- Unions: A union is a type of structure that can be used where the amount of memory used is a key factor. Unions can be used when no more than one member needs to be accessed at a time. That way, we can save some memory instead of using a struct.

You may also like Pokhara University || Spring ,2016 || Programming Language

Be the first to comment

Leave a Reply

Your email address will not be published.


*