C Technical Questions and Answers

Started by Kalyan, Dec 01, 2008, 01:43 PM

previous topic - next topic
Go Down


C Technical Questions and Answers

What are the different storage classes in C?

C has three types of storage: automatic, static and allocated.

Variable having block scope and without static specifier have automatic storage duration.

Variables with block scope, and with static specifier have static scope. Global variables (i.e, file scope) with or without the the static specifier also have static scope.

Memory obtained from calls to malloc(), alloc() or realloc() belongs to allocated storage class.

What is the difference between strings and character arrays?

A major difference is: string will have static storage duration, whereas as a character array will not, unless it is explicity specified by using the static keyword.

Actually, a string is a character array with following properties:

* the multibyte character sequence, to which we generally call string, is used to initialize an array of static storage duration. The size of this array is just sufficient to contain these characters plus the terminating NUL character.

* it not specified what happens if this array, i.e., string, is modified.

* Two strings of same value[1] may share same memory area. For example, in the following declarations:

char *s1 = "Calvin and Hobbes";
char *s2 = "Calvin and Hobbes";

the strings pointed by s1 and s2 may reside in the same memory location. But, it is not true for the following:

char ca1[] = "Calvin and Hobbes";
char ca2[] = "Calvin and Hobbes";

[1] The value of a string is the sequence of the values of the contained characters, in order.

Write down the equivalent pointer expression for referring the same element a[j][k][l]?

a == *(a+i)
a[j] == *(*(a+i)+j)
a[j][k] == *(*(*(a+i)+j)+k)
a[j][k][l] == *(*(*(*(a+i)+j)+k)+l)

Which bit wise operator is suitable for checking whether a particular bit is on or off?

The bitwise AND operator. Here is an example:

enum {
KBit0 = 1,

if ( some_int & KBit24 )
printf ( "Bit number 24 is ON\n" );
printf ( "Bit number 24 is OFF\n" );

Which bit wise operator is suitable for turning off a particular bit in a number?

The bitwise AND operator, again. In the following code snippet, the bit number 24 is reset to zero.
some_int = some_int & ~KBit24;

Which bit wise operator is suitable for putting on a particular bit in a number?

The bitwise OR operator. In the following code snippet, the bit number 24 is turned ON:
some_int = some_int | KBit24;

source : interviewghost

Go Up

Quick Reply

With Quick-Reply you can write a post when viewing a topic without loading a new page. You can still use bulletin board code and smileys as you would in a normal post.

Warning: this topic has not been posted in for at least 120 days.
Unless you're sure you want to reply, please consider starting a new topic.

Note: this post will not display until it's been approved by a moderator.
Please leave this box empty:

Type the letters shown in the picture
Listen to the letters / Request another image

Type the letters shown in the picture:

shortcuts: alt+s submit/post or alt+p preview
Network of IT Acumens | GinGly :: SMS Backup | Acumen :: Discussion Board | AshokPillar :: Hosting | CineBuzz :: Latest Cinema News | My Kids Diary :: Capture your kids magical moment
Copyright © 2005 - 2016 :: IT Acumens :: All Rights Reserved.
ITAcumens Forum with 2 lakhs post running for 10 years - Powered by HostGator Dedicated Server