C - LANGUAGE

C Language is A High-level And General-purpose programming Language that Is Ideal For Developing Firmware Or Portable Applications.

1.What is C language?

The C programming language is a standardized programming language developed in the early 1970s by
Ken Thompson and Dennis Ritchie for use on the UNIX operating system. It has since spread to many
other operating systems, and is one of the most widely used programming languages. C is prized for its
efficiency, and is the most popular programming language for writing system software, though it is also
used for writing applications.

2.What does static variable mean?

There are 3 main uses for the static.

1. If you declare within a function: It retains the value between function calls

2. If it is declared for a function name: By default function is extern..so it will be visible from other files if
the function declaration is as static..it is invisible for the outer files

3. Static for global variables: By default we can use the global variables from outside files If it is static
global..that variable is limited to with in the file.

#include
int t = 10;
main(){
int x = 0;
void funct1();
funct1();
printf("After first call \n");
funct1();
printf("After second call \n");

funct1();
printf("After third call \n");
}
void funct1()
{
static int y = 0;
int z = 10;
printf("value of y %d z %d",y,z);
y=y+10;
}

JOBSMATE.COM

value of y 0 z 10 After first call
value of y 10 z 10 After second call
value of y 20 z 10 After third call

3.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 static specifier also have static scope.
Memory obtained from calls to malloc(), alloc() or realloc() belongs to allocated storage class.

4.What is hashing?

To hash means to grind up, and that's essentially what hashing is all about. The heart of a hashing
algorithm is a hash function that takes your nice, neat data and grinds it into some random-looking integer.
The idea behind hashing is that some data either has no inherent ordering (such as images) or is expensive
to compare (such as images). If the data has no inherent ordering, you cant perform comparison searches.

5.Can static variables be declared in a header file?

You cant declare a static variable without defining it as well (this is because the storage class modifiers
static and extern are mutually exclusive). A static variable can be defined in a header file, but this would
cause each source file that included the header file to have its own private copy of the variable, which is
probably not what was intended.

6.Can a variable be both constant and volatile?

Yes. The const modifier means that this code cannot change the value of the variable, but that does not
mean that the value cannot be changed by means outside this code. The function itself did not change the
value of the timer, so it was declared const. However, the value was changed by hardware on the computer,
so it was declared volatile. If a variable is both const and volatile, the two modifiers can appear in either
order.

7.Can include files be nested?

Yes. Include files can be nested any number of times. As long as you use precautionary measures, you can
avoid including the same file twice. In the past, nesting header files was seen as bad programming practice,
because it complicates the dependency tracking function of the MAKE program and thus slows down
compilation.Many of today's popular compilers make up for this difficulty by implementing a concept called precompiled
headers, in which all headers and associated dependencies are stored in a precompiled state.

8.What is a null pointer?

There are times when its necessary to have a pointer that doesn't point to anything. The macro NULL,
defined in , has a value that's guaranteed to be different from any valid pointer. NULL is a literal zero,
possibly cast to void* or char*.

Some people, notably C++ programmers, prefer to use 0 rather than NULL.
The null pointer is used in three ways:
1) To stop indirection in a recursive data structure.
2) As an error value.
3) As a sentinel value.

9.What is the output of printf("%d") ?

When we write printf("%d",x); this means compiler will print the value of x. But as here, there is nothing
after %d so compiler will show in output window garbage value.

10.What is the difference between calloc() and malloc() ?

calloc(...) allocates a block of memory for an array of elements of a certain size. By default the block is
initialized to 0. The total number of memory allocated will be (number_of_elements * size).

malloc(...) takes in only a single argument which is the memory required in bytes. malloc(...) allocated bytes
of memory and not blocks of memory like calloc(...).

malloc(...) allocates memory blocks and returns a void pointer to the allocated space, or NULL if there is
insufficient memory available.

calloc(...) allocates an array in memory with elements initialized to 0 and returns a pointer to the allocated
space. calloc(...) calls malloc(...) in order to use the C++ _set_new_mode function to set the new handler
mode.

11.What is the difference between printf() and sprintf() ?

sprintf() writes data to the character array whereas printf(...) writes data to the standard output device.

12.How to reduce a final size of executable?

Size of the final executable can be reduced using dynamic linking for libraries.

13.Can you tell me how to check whether a linked list is circular?

Create two pointers, and set both to the start of the list. Update each as follows:

while (pointer1) {
pointer1 = pointer1->next;
pointer2 = pointer2->next;
if (pointer2) pointer2=pointer2->next;
if (pointer1 == pointer2) {
print ("circular");
}
}

If a list is circular, at some point pointer2 will wrap around and be either at the item just before pointer1,
or the item before that. Either way, its either 1 or 2 jumps until they meet.

14.Advantages of a macro over a function?

Macro gets to see the Compilation environment, so it can expand __ __TIME__ __FILE__ #defines. It is
expanded by the preprocessor.

For example, you can do this without macros
#define PRINT(EXPR) printf( #EXPR %d\n EXPR)
PRINT( 5+6*7 ) // expands into printf(5+6*7=%d5+6*7 );
you can define your mini language with macros:
#define strequal(A,B) (!strcmp(A,B))

15.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 explicitly 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.

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

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

17.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,
KBit1,
KBit31,
};

JOBSMATE.COM

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

18.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;

19.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;

20.Does there exist any other function which can be used to convert an integer or a float to a string?

Some implementations provide a nonstandard function called itoa(), which converts an integer to string.

#include
char *itoa(int value, char *string, int radix);
DESCRIPTION
The itoa() function constructs a string representation of an integer.
PARAMETERS
value: Is the integer to be converted to string representation.
string: Points to the buffer that is to hold resulting string.
The resulting string may be as long as seventeen bytes.
radix: Is the base of the number; must be in the range 2 - 36.
A portable solution exists. One can use sprintf():
char s[SOME_CONST];
int i = 10;
float f = 10.20;
sprintf ( s, %d %f\n,i, f );

21.Why does malloc(0) return valid memory address ? What's the use?

malloc(0) does not return a non-NULL under every implementation. An implementation is free to behave
in a manner it finds suitable, if the allocation size requested is zero. The implmentation may choose any of
the following actions:

* A null pointer is returned.
* The behavior is same as if a space of non-zero size was requested. In this case, the usage of return value
yields to undefined-behavior.

Notice, however, that if the implementation returns a non-NULL value for a request of a zero-length
space, a pointer to object of ZERO length is returned! Think, how an object of zero size should be
represented

For implementations that return non-NULL values, a typical usage is as follows:
void
func ( void )
{
int *p; /* p is a one-dimensional array, whose size will vary during the the lifetime of the program */
size_t c;
p = malloc(0); /* initial allocation */

if (!p)
{
perror (?FAILURE? );
return;
}
/* */

while (1)
{
c = (size_t) ; /* Calculate allocation size */
p = realloc ( p, c * sizeof *p );
/* use p, or break from the loop */
/* */
}
return;
}
Notice that this program is not portable, since an implementation is free to return NULL for a malloc(0)
request, as the C Standard does not support zero-sized objects.

22.Difference between const char* p and char const* p

In const char* p, the character pointed by p is constant, so u cant change the value of character pointed by
p but u can make p refer to some other location.

In char const* p, the ptr ?p? is constant not the character referenced by it, so u cant make p to reference to
any other location but u can change the value of the char pointed by p

23.What is the result of using Option Explicit?

  • 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:\COMPILER\INCLUDE;S:\SOURCE\HEADERS; using the #include version of file
inclusion, the compiler first checks the C:\COMPILER\INCLUDE directory for the specified file. If the
file is not found there, the compiler then checks the S:\SOURCE\HEADERS 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.
  • The #include file 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.

24.What is the benefit of using an enum rather than a #define constant?

The use of an enumeration constant (enum) has many advantages over using the traditional symbolic
constant style of #define. These advantages include a lower maintenance requirement, improved program
readability, and better debugging capability.
1) The first advantage is that enumerated constants are generated automatically by the compiler.
Conversely, symbolic constants must be manually assigned values by the programmer.

2) Another advantage of using the enumeration constant method is that your programs are more readable and
thus can be understood better by others who might have to update your program later.

3) A third advantage to using enumeration constant

25.Can we have a pointer to a function?

a. Not possible

b. Possible

c. Depends on the return value

d. Depends on the # of arguments

Answer:b.Possible

26.Write a function to swaps the values of two integers.

a. No solution exist.

b. Solution need 2 extra variables

c Solution exist without any extra variables

d. Solution need 1 extra variable

Solution c Solution exist without any extra variables

1. void swap(int a, int b)
{
int c;
c=a;
a=b;
b=c;
}

JOBSMATE.COM

2. void swap (int a, int b)
{

a=a+b;

b=a-b;

a=a-b;

}
Solution2 is the best solution since no extra variable is required.

27.Which of the following Bitwise operators can be used efficiently to swap two numbers? a. & b. ^ c. | d. ||

Solution:b ^

a=a^b
b=a^b
a=a^b Now ‘a’ will have ‘b’s initial value and wise-versa.

28.Do you find any issue with the above snippet of code?

a. No issues

b. P is a bad pointer

c P is a void pointer

d. Both 2& 3

Answer: b. P is a bad pointer

When a pointer is first allocated, it does not have a pointee. The pointer is "uninitialized" or simply "bad". A
de-reference operation on a bad pointer is a serious run-time error. If you are lucky, the de-reference
operation will crash or halt immediately (Java behaves this way). If you are unlucky, the bad pointer
de-reference will corrupt a random area of memory, slightly altering the operation of the program so that it
goes wrong some indefinite time later. Each pointer must be assigned a pointee before it can support
de-reference operations. Before that, the pointer is bad and must not be used. Bad pointers are very
common. In fact, every pointer starts out with a bad value. Correct code overwrites the bad value with a
correct reference to a pointee, and thereafter the pointer works fine. There is nothing automatic that gives a
pointer a valid pointee.

JOBSMATE.COM

void BadPointer()
{

int* p; // allocate the pointer, but not the pointee

*p = 42; // this de-reference is a serious runtime error

}

29.Can we have a pointer to a function?

a. Not possible

b. Possible

c. Depends on the return value

d. Depends on the # of arguments

Answer:b.Possible

void func(int a)
{
}
void main()
{
void (*fp)(int);
fp=func;
fp(1);
}

30.Write a function to swaps the values of two integers.

a. No solution exist.

b. Solution need 2 extra variables

c Solution exist without any extra variables

d. Solution need 1 extra variable

Solution c Solution exist without any extra variables

1. void swap(int a, int b)
{
int c;
c=a;
a=b;
b=c;
}

2. void swap (int a, int b)
{

a=a+b;

b=a-b;

a=a-b;

}
Solution2 is the best solution since no extra variable is required.

31.Do you find any issue with the above snippet of code?

a. No issues

b. P is a bad pointer

c P is a void pointer

d. Both 2& 3

Answer: b. P is a bad pointer

When a pointer is first allocated, it does not have a pointee. The pointer is "uninitialized" or simply "bad". A
de-reference operation on a bad pointer is a serious run-time error. If you are lucky, the de-reference operation will
crash or halt immediately (Java behaves this way). If you are unlucky, the bad pointer de-reference will corrupt a
random area of memory, slightly altering the operation of the program so that it goes wrong some indefinite time later.
Each pointer must be assigned a pointee before it can support de-reference operations. Before that, the pointer is bad
and must not be used. Bad pointers are very common. In fact, every pointer starts out with a bad value. Correct code
overwrites the bad value with a correct reference to a pointee, and thereafter the pointer works fine. There is nothing
automatic that gives a pointer a valid pointee.

void BadPointer()
{

int* p; // allocate the pointer, but not the pointee

*p = 42; // this de-reference is a serious runtime error

}

32.void add(int a, int b) { int c; c = a + b; add (1,1); } What is the result of above funtion?

a. Sum of a,b,1

b. Results in Buffer Overflow

c Results in Compiler Error

d Results in Stack Overflow

Answer: d. Results in Stack Overflow

When a function is called recursively, sometimes infinite recursions occur which results in STACK OVERFLOW. What
does it mean? Well when a function is called,

1. First it will evaluate actual parameter expressions.

2. Then, memory is allocated to local variables.

3. Store caller’s current address of execution (return address of the current function) and then continue execute the
recursive call.

4. Then it executes rest of the function body and reaches end and returns to the caller’s address.

Now when a function is infinitely called (recursively) without a proper condition to check its recursive, then only first 3
steps keep executing and function will never reach step 4 to finish execution and return to previous function. In this
way, function will keep allocating memory and at some point of time it will go out of memory or reaches stack limit and
will never be able to accommodate another function and hence crashes. This is called stack overflow.

33.Which of the following will initialize the new memory to 0 ?

a. malloc

b. free

c. new

d delete

Answer: c. new

“new” will initlize the new memory to 0 but “malloc()” gives random value in the new alloted memory location

34.Which of the following standard C library converts a string to a long integer and reports any .leftover. numbers that could not be converteda. atol b. atoi c. stol d. strtol.

Answer: d. strtol

strtol() Converts a string to a long integer and reports any .leftover. numbers that could not be converted.
atoi() Converts a string to an integer.
atol() Converts a string to a long integer.

35.How do you construct an increment statement or decrement statement in C?

There are actually two ways you can do this. One is to use the increment operator ++ and
decrement operator. For example, the statement means to increment the value of x by 1. Likewise, the
statement x means to decrement the value of x by 1. Another way of writing increment statements is to use
the conventional + plus sign or minus sign. In the case of x++, another way to write it is x= x +1?.

36.Some coders debug their programs by placing comment symbols on some codes instead of deleting it. How does this aid in debugging?

Placing comment symbols /* */ around a code, also referred to as commenting out, is a way of
isolating some codes that you think maybe causing errors in the program, without deleting the code. The
idea is that if the code is in fact correct, you simply remove the comment symbols and continue on. It also
saves you time and effort on having to retype the codes if you have deleted it in the first place.

37.What is the equivalent code of the following statement in WHILE LOOP format?

[c]
for (a=1; a&lt;=100; a++)
printf (&quot;%d\n&quot;, a * a);
[/c]

Answer:[c]
a=1;
while (a&lt;=100) { printf (&quot;%d\n&quot;, a * a); a++;}
[/c]

38.What is spaghetti programming?

Spaghetti programming refers to codes that tend to get tangled and overlapped throughout the
program. This unstructured approach to coding is usually attributed to lack of experience on the part of the
programmer. Spaghetti programming makes a program complex and analyzing the codes difficult, and so
must be avoided as much as possible.

39.In C programming, how do you insert quote characters (and ) into the output screen?

This is a common problem for beginners because quotes are normally part of a printf statement.
To insert the quote character as part of the output, use the format specifiers \? (for single quote), and \? (for
double quote).

40.What is the use of a '0' character?

It is referred to as a terminating null character, and is used primarily to show the end of a string
value.

41.What is the difference between the = symbol and == symbol?

The = symbol is often used in mathematical operations. It is used to assign a value to a given
variable. On the other hand, the == symbol, also known as equal to or equivalent to, is a relational operator
that is used to compare two values.

42.Which of the following operators is incorrect and why? ( >=, <=, <>, ==)

<> is incorrect. While this operator is correctly interpreted as not equal to in writing conditional
statements, it is not the proper operator to be used in C programming. Instead, the operator != must be
used to indicate not equal to condition.

43.Can the curly brackets { } be used to enclose a single line of code?

While curly brackets are mainly used to group several lines of codes, it will still work without
error if you used it for a single line. Some programmers prefer this method as a way of organizing codes to
make it look clearer, especially in conditional statements.

44.What are header files and what are its uses in C programming?

Header files are also known as library files. They contain two essential things: the definitions and
prototypes of functions being used in a program. Simply put, commands that you use in C programming
are actually functions that are defined from within each header files. Each header file contains a set of
functions. For example: stdio.h is a header file that contains definition and prototypes of commands like
printf and scanf.

45.Can I use int data type to store the value 32768? Why?

No. Int data type is capable of storing values from -32768 to 32767. To store 32768, you can use
long int instead. You can also use unassigned int assuming you don’t intend to store negative values.

46.Can two or more operators such as \n and \t be combined in a single line of program code

Yes, it's perfectly valid to combine operators, especially if the need arises. For example: you can
have a code like printf (Hello\n\n\World\) to output the text Hello on the first line and World enclosed in
single quotes to appear on the next two lines.

47.Why is it that not all header files are declared in every C program?

The choice of declaring a header file at the top of each C program would depend on what
commands/functions you will be using in that program. Since each header file contains different function
definitions and prototype, you would be using only those header files that would contain the functions you
will need. Declaring all header files in every program would only increase the overall file size and load of
the program, and is not considered a good programming style.

48.When is the void keyword used in a function?

When declaring functions, you will decide whether that function would be returning a value or
not. If that function will not return a value, such as when the purpose of a function is to display some
outputs on the screen, then ?void? is to be placed at the leftmost part of the function header. When a return
value is expected after the function execution, the data type of the return value is placed instead of void

49.What are compound statements?

Compound statements are made up of two or more program statements that are executed together.
This usually occurs while handling conditions wherein a series of statements are executed when a TRUE
or FALSE is evaluated. Compound statements can also be executed within a loop. Curly brackets { } are
placed before and after compound statements.

50.Write a loop statement that will show the following output: 1 12 123 1234 12345

[c]
for (a=1; a&lt;=5; i++) {
for (b=1; b&lt;=a; b++)
printf(&quot;%d&quot;,b);
printf(&quot;\n&quot;);
}
[/c]

51.What is wrong in this statement? scanf(%d, whatnumber);

An ampersand & symbol must be placed before the variable name what number. Placing &
means whatever integer value is entered by the user is stored at the address of the variable name. This is a
common mistake for programmers, often leading to logical errors.

52.How do you generate random numbers in C?

Random numbers are generated in C using the rand() command. For example: anyNum = rand()
will generate any integer number beginning from 0, assuming that anyNum is a variable of type integer.

53.What could possibly be the problem if a valid function name such as tolower() is being reported by the C compiler as undefined?

The most probable reason behind this error is that the header file for that function was not indicated at the
top of the program. Header files contain the definition and prototype for functions and commands used in a
C program. In the case of tolower(), the code #include <ctype.h>must be present at the beginning of the
program.

54.What does the format %10.2 mean when included in a printf statement?

This format is used for two things: to set the number of spaces allotted for the output number and
to set the number of decimal places. The number before the decimal point is for the allotted space, in this
case it would allot 10 spaces for the output number. If the number of space occupied by the output number
is less than 10, addition space characters will be inserted before the actual output number. The number
after the decimal point sets the number of decimal places, in this case, it’s 2 decimal spaces.

55.What is wrong with this statement? myName = Robin;

You cannot use the = sign to assign values to a string variable. Instead, use the strcpy function.
The correct statement would be: strcpy(myName, Robin);

56.How do you determine the length of a string value that was stored in a variable?

To get the length of a string value, use the function strlen(). For example, if you have a variable
named FullName, you can get the length of the stored string value by using this statement: I =
strlen(FullName); the variable I will now have the character length of the string value.

57.Is it possible to initialize a variable at the time it was declared?

Yes, you don't have to write a separate assignment statement after the variable declaration, unless
you plan to change it later on. For example: char planet[15] = Earth does two things: it declares a string
variable named planet, then initializes it with the value Earth

58.What are the different file extensions involved when programming in C?

Source codes in C are saved with .C file extension. Header files or library files have the .H file
extension. Every time a program source code is successfully compiled, it creates an .OBJ object file, and
an executable .EXE file.

59.What are reserved words?

Reserved words are words that are part of the standard C language library. This means that
reserved words have special meaning and therefore cannot be used for purposes other than what it is
originally intended for. Examples of reserved words are int, void, and return.

60.What are linked list?

A linked list is composed of nodes that are connected with another. In C programming, linked
lists are created using pointers. Using linked lists is one efficient way of utilizing memory for storage.

61.What are binary trees?

Binary trees are actually an extension of the concept of linked lists. A binary tree has two
pointers, a left one and a right one. Each side can further branch to form additional nodes, which each node
having two pointers as well.

62.Not all reserved words are written in lowercase. TRUE or FALSE?

FALSE. All reserved words must be written in lowercase; otherwise the C compiler would
interpret this as unidentified and invalid.

63.What is wrong with this program statement? void = 10;

The word void is a reserved word in C language. You cannot use reserved words as a
user-defined variable.

64.Is this program statement valid? INT = 10.50;

Assuming that INT is a variable of type float, this statement is valid. One may think that INT is a
reserved word and must not be used for other purposes. However, recall that reserved words are express in
lowercase, so the C compiler will not interpret this as a reserved word.

65.What is a newline escape sequence?

A newline escape sequence is represented by the \n character. This is used to insert a new line
when displaying data in the output screen. More spaces can be added by inserting more \n characters. For
example, \n\n would insert two spaces. A newline escape sequence can be placed before the actual output
expression or after.

66.What is output redirection?

It is the process of transferring data to an alternative output source other than the display screen.
Output redirection allows a program to have its output saved to a file. For example, if you have a program
named COMPUTE, typing this on the command line as COMPUTE >DATA can accept input from the
user, perform certain computations, then have the output redirected to a file named DATA, instead of
showing it on the screen.

67.What is the difference between functions abs() and fabs()?

These 2 functions basically perform the same action, which is to get the absolute value of the
given value. Abs() is used for integer values, while fabs() is used for floating type numbers. Also, the
prototype for abs() is under <stdlib.h>, while fabs() is under <math.h>.

68.Write a simple code fragment that will check if a number is positive or negative.

:[c]

If (num&gt;=0)
printf(&quot;number is positive&quot;);
else
printf (&quot;number is negative&quot;);
[/c]

69.What does the function toupper() do?

It is used to convert any letter to its upper case mode. Toupper() function prototype is declared in
<ctype.h>. Note that this function will only convert a single character, and not an entire string.

70.Which function in C can be used to append a string to another string?

The strcat function. It takes two parameters, the source string and the string value to be appended
to the source string.

71.Do these two program statements perform the same output? 1) scanf(?%c?, &letter); 2) letter=getchar()

Yes, they both do the exact same thing, which is to accept the next key pressed by the user and
assign it to variable named letter.

72.What is the difference between text files and binary files?

Text files contain data that can easily be understood by humans. It includes letters, numbers and
other characters. On the other hand, binary files contain 1s and 0s that only computers can interpret.

73.is it possible to create your own header files?

Yes, it is possible to create a customized header file. Just include in it the function prototypes that
you want to use in your program, and use the #include directive followed by the name of your header file.

74.What is dynamic data structure?

Dynamic data structure provides a means for storing data more efficiently into memory. Using
dynamic memory allocation, your program will access memory spaces as needed. This is in contrast to
static data structure, wherein the programmer has to indicate a fix number of memory space to be used inthe program.

75.The % symbol has a special use in a printf statement. How would you place this character as part of the output on the screen?

You can do this by using %% in the printf statement. For example, you can write printf(?10%%?)
to have the output appear as 10% on the screen.

76.What are the advantages and disadvantages of a heap?

Storing data on the heap is slower than it would take when using the stack. However, the main
advantage of using the heap is its flexibility. That’s because memory in this structure can be allocated and
remove in any particular order. Slowness in the heap can be compensated if an algorithm was well
designed and implemented.

77.Explain what objective-C program basically consists of?

Objective-C program basically consists of

  • Preprocessor commands
  • Interface
  • Implementation
  • Method
  • Variables
  • Statements & Expressions
  • Comments

78.Explain what is OOP?

OOP means Object Oriented Programming; it is a type of programming technique that helps to manage a set
of objects in a system. With the help of various programming languages, this method helps to develop several
computer programs and applications.

79.Explain what is the protocol in Objective C?

In Objective-C, a protocol is a language feature, that provides multiple inheritances in a single inheritance
language. Objective C supports two types of protocol.

  • Ad hoc protocols known as informal protocol
  • Compiler protocols known as a formal protocol

80.Explain what is the difference between polymorphism and abstraction?

Abstraction in OOP is the process of reducing the unwanted data and maintaining only the relevant data for
the users while polymorphism enables an object to execute their functions in two or more forms.

81.Explain what is parsing and mention which class can we use for passing of XML in iphone?

Parsing is the process referred to access the data in the XML element. We can use class “NSXML” parser
for passing XML in iphone.

82.Mention which class are used to establish a connection between applications to the web server?

The class used to establish connection between applications to web server are

  • NSURL
  • NSURL REQUEST
  • NSURL CONNECTION

83.Explain what is an accessor methods?

Accessor methods are methods belonging to a class that enables you to get and set the values of instance
valuable contained within the class.

84.Explain what is #import?

#import is a C pre-processor construct to avoid multiple inclusions of the same file.

85.Mention what is the class of a constant string?

It’s and NXConstantString. NXConstantString *myString = @ “my string”;

86.List out the methods used in NSURL connection?

Methods used in NSURL connection are

  • Connection did receive response
  • Connection did receive data
  • Connection fail with error
  • Connection did finish loading

87.Explain class definition in Objective-C?

A class definition begins with the keyword @interface followed by the interface (class) name, and the
class body, closed by a pair of curly braces. In Objective-C, all classed are retrieved from the base class
called NSObject. It gives basic methods like memory allocation and initialization.

88.Mention what is the use of category in Objective-C?

The use of category in Objective-C is to extend an existing class by appending behavior that is useful only
in certain situations. In order to add such extension to existing classes, objective –C provides extensions
and categories. The syntax used to define a category is @interface keyword.

89.Explain what are the characteristics of the category?

Characteristics of category includes

  • Even if you don’t have the original source code for implementation, a category can be declared for any

class

  • Any methods that you define in a category will be available to all instances of the original class as well as

any sub-classes for the original class

 

  • At runtime, there is no variation between a method appended by a category and one that is implemented by

the original class

90.Explain what is single inheritance in Objective-C?

Objective-c subclass can only be obtained from a single direct parent class this concept is known as
“single inheritance” .

91.Explain what is polymorphism in Objective-C?

Polymorphism in Objective-C is referred to a capability of base class pointer to call the function.

92.Explain when to use NSArray and NSMutableArray?

NSArray: You will use an NS array when data in the array don’t change. For example, the company name
you will put in NS Array so that no one can manipulate it.

NSMutableArray: This array will be used in an array, when data in an array will change. For instance, if
you are passing an array to function and that function will append some elements in that array then you
will choose NSMutable Array.

93.Explain what is synthesized in Objective-C?

Once you have declared the property in objective-C, you have to tell the compiler instantly by using
synthesize directive. This will tell the compiler to generate a getter & setter message.

94.Explain how string is represented in Objective-C?

In Objective-C, the string is represented by using NSS string and its sub-class NSMutableString provides
several ways for creating string objects.

95.Explain what is data encapsulation in Objective-C?

In Objective-C, data encapsulation is referred to the mechanism of connecting the data and the functions
that use them.

96.Explain how to call the function in Objective-C?

To call the function in Objective-C, you have to do Account -> Object Name -> Display account
information -> Method name

97.Explain what are objective- C blocks?

In Objective-C class, there is an object that combines data with related behavior. It enables you to form
distinct segments of code that can be passed around to functions or methods as if they were values.
Objective-C blocks can be added to collections like NSDictionary or NSArray.

98.Explain what is the main difference between the function calls and messages?

The main difference between function call and message is that a function and its arguments are linked
together in the compiled code, but a message and a receiving object are not linked until the program is
executing and the message is sent.

99.Explain how messaging works in Objective-C?

Messaging are not bound to method implementation until runtime in Objective-C. The compiler transforms
a message expression, into a call on a messaging function, objc_msgSend(). This function connects the
receiver and the name of the method mentioned in the message.

100.Explain how the class “IMPLEMENTATION” is represented in Objective-C?

In Objective-C the class “ IMPLEMENTATION” is represented with @implementation directive and
ends with @end.

101.Explain what is dot notation?

Dot notation involves assessing an instance variable by determining a class “instance” followed by a “dot”
followed in turn by the name of instance variable or property to be accessed.

102.Mention whether NS object is a parent class or derived class?

NS object is the parent class and consists of a number of instance variables and instance methods.

103.What is the reuse Identifier used for?

The reuse Identifier is used to indicate that a cell can be reused in a UITableView. For example when the
cell looks the same, but has different content. The UITableView will maintain an internal cache of
UITableViewCell’s with the reuse Identifier and allow them to be reused when
dequeueReusableCellWithIdentifier: is called. By reusing table cell’s the scroll performance of the table
view is better because new views do not need to be created.

104.Explain the difference between atomic and nonatomic synthesized properties?

Atomic and nonatomic refers to whether the setters/getters for a property will atomically read and write
values to the property. When the atomic keyword is used on a property, any access to it will be
“synchronized”. Therefore a call to the getter will be guaranteed to return a valid value, however this does
come with a small performance penalty. Hence in some situations nonatomic is used to provide faster
access to a property, but there is a chance of a race condition causing the property to be nil under rare
circumstances (when a value is being set from another thread and the old value was released from memory
but the new value hasn’t yet been fully assigned to the location in memory for the property).

105.Explain the difference between copy and retain?

Retaining an object means the retain count increases by one. This means the instance of the object will be
kept in memory until it’s retain count drops to zero. The property will store a reference to this instance and
will share the same instance with anyone else who retained it too. Copy means the object will be cloned
with duplicate values. It is not shared with any one else.

106.What’s the difference between not running, inactive, active, background and suspended execution states?

Not running: The app has not been launched or was running but was terminated by the system.

Inactive: The app is running in the foreground but is currently not receiving events. (It may be executing
other code though.) An app usually stays in this state only briefly as it transitions to a different state.

Active: The app is running in the foreground and is receiving events. This is the normal mode for
foreground apps.

Background: The app is in the background and executing code. Most apps enter this state briefly on their
way to being suspended. However, an app that requests extra execution time may remain in this state for a
period of time. In addition, an app being launched directly into the background enters this state instead of
the extra execution time may remain in this state for a period of time. In addition, an app being launched
directly into the background enters this state instead of the inactive state.

Suspended: The app is in the background but is not executing code. The system moves apps to this state
automatically and does not notify them before doing so. While suspended, an app remains in memory but
does not execute any code. When a low memory condition occurs, the system may purge suspended apps
without notice to make more space for the foreground app.

107.What is a category and when is it used?

A category is a way of adding additional methods to a class without extending it. It is often used to add a
collection of related methods. A common use case is to add additional methods to built in classes in the
Cocoa frameworks. For example adding async download methods to the UIImage class.

108.What is the difference between viewDidLoad and viewDidAppear? Which should you use to load data from a remote server to display in the view?

viewDidLoad is called when the view is loaded, whether from a Xib file, storyboard or programmatically
created in loadView. viewDidAppear is called every time the view is presented on the device. Which to
use depends on the use case for your data. If the data is fairly static and not likely to change then it can be
loaded in viewDidLoad and cached. However if the data changes regularly then using viewDidAppear to
load it is better. In both situations, the data should be loaded asynchronously on a background thread to
avoid blocking the UI.

109.What considerations do you need when writing a UITableViewController which shows images downloaded from a remote server?

This is a very common task in iOS and a good answer here can cover a whole host of knowledge. The
important piece of information in the question is that the images are hosted remotely and they may take
time to download, therefore when it asks for “considerations”, you should be talking about:

  • Only download the image when the cell is scrolled into view, i.e. when cellForRowAtIndexPath is called.
  • Downloading the image asynchronously on a background thread so as not to block the UI so the user can

keep scrolling.

  • When the image has downloaded for a cell we need to check if that cell is still in the view or whether it has

been reused by another piece of data. If it’s been reused then we should discard the image, otherwise we
need to switch back to the main thread to change the image on the cell.

110.What is a protocol, how do you define your own and when is it used?

A protocol is similar to an interface from Java. It defines a list of required and optional methods that a
class must/can implement if it adopts the protocol. Any class can implement a protocol and other classes
can then send messages to that class based on the protocol methods without it knowing the type of the
class.

@protocol MyCustomDataSource

? (NSUInteger)numberOfRecords;

? (NSDictionary *)recordAtIndex:(NSUInteger)index;

@optional

? (NSString *)titleForRecordAtIndex:(NSUInteger)index;

@end

A common use case is providing a DataSource for UITableView or UICollectionView.

111.What is the Responder Chain?

When an event happens in a view, for example a touch event, the view will fire the event to a chain of
UIResponder objects associated with the UIView. The first UIResponder is the UIView itself, if it does not
handle the event then it continues up the chain to until UIResponder handles the event. The chain will
include UIViewControllers, parent UIViews and their associated UIViewControllers, if none of those
handle the event then the UIWindow is asked if it can handle it and finally if that doesn't handle the event
then the UIApplicationDelegate is asked.

112.How would you create your own custom view?

By Subclassing the UIView class.

113.What is fast enumeration?

Fast enumeration is a language feature that allows you to enumerate over the contents of a collection.
(Your code will also run faster because the internal implementation reduces message send overhead and
increases pipelining potential.)

114.What is a struct?

A struct is a special C data type that encapsulates other pieces of data into a single cohesive unit. Like an
object, but built into C.

115.What are mutable and immutable types in Objective C?

Mutable means you can change its contents later but when you mark any object immutable, it means once
they are initialized, their values cannot be changed. For example, NSArray, NSString values cannot be
changed after initialized.

116.Explain retain counts?

Retain counts are the way in which memory is managed in Objective?C. When you create an object, it has
a retain count of 1. When you send an object a retain message, its retain count is incremented by 1. When
you send an object a release message, its retain count is decremented by 1. When you send an object a auto
release message, its retain count is decremented by 1 at some stage in the future. If an objects retain count
is reduced to 0, it is de allocated.

117.What is the difference between frame and bounds?

The frame of a view is the rectangle, expressed as a location (x,y) and size (width, height) relative to the
super view it is contained within. The bounds of a view is the rectangle, expressed as a location (x,y) and
size (width, height) relative to its own coordinate system (0,0).

118.Is a delegate retained?

No, the delegate is never retained! Ever!

119.If I call performSelector:withObject:afterDelay: – is the object retained?

Yes, the object is retained. It creates a timer that calls a selector on the current threads run loop. It may not
be 100% precise time wise as it attempts to dequeue the message from the run loop and perform the
selector.

120.Can you explain what happens when you call auto release on an object?

When you send an object a auto release message, its retain count is decremented by 1 at some stage in the
future. The object is added to an auto release pool on the current thread. The main thread loop creates an
auto release pool at the beginning of the function, and release it at the end. This establishes a pool for the
lifetime of the task. However, this also means that any auto released objects created during the lifetime of
the task are not disposed of until the task completes. This may lead to the task's memory footprint
increasing unnecessarily. You can also consider creating pools with a narrower scope or use
NSOperationQueue with it?s own auto release pool. (Also important – You only release or auto release
objects you own.)

121.What is the NSCoder class used for?

NSCoder is an abstract Class which represents a stream of data. They are used in Archiving and
Unarchiving objects. NSCoder objects are usually used in a method that is being implemented so that the
class conforms to the protocol. (which has something like encode Object and decode Object methods in
them).

122.What is an NSOperationQueue and how/would you use it?

The NSOperationQueue class regulates the execution of a set of NSOperation objects. An operation queue
is generally used to perform some asynchronous operations on a background thread so as not to block the
main thread.

123.Explain the correct way to manage Outlets memory

Create them as properties in the header that are retained. In the viewDidUnload set the outlets to nil(i.e
self.outlet = nil). Finally in dealloc make sure to release the outlet.

124.Is the delegate for a CAAnimation retained?

Yes it is!! This is one of the rare exceptions to memory management rules.

125.Explain the difference between NSOperationQueue concurrent and non?concurrent.

In the context of an NSOperation object, which runs in an NSOperationQueue, the terms concurrent and
nonconcurrent do not necessarily refer to the side?by?side execution of threads. Instead, a non?concurrent
operation is one that executes using the environment that is provided for it while a concurrent operation is
responsible for setting up its own execution environment.

126.What is Automatic Reference Counting (ARC) ?

ARC is a compiler?level feature that simplifies the process of managing the lifetimes of Objective?C
objects. Instead of you having to remember when to retain or release an object, ARC evaluates the lifetime
requirements of your objects and automatically inserts the appropriate method calls at compile time.

127.What is the difference between delegates and notifications?

We can use notifications for a variety of reasons. For example, you could broadcast a notification to
change how user?interface elements display information based on a certain event elsewhere in the program.
Or you could use notifications as a way to ensure that objects in a document save their state before the
document window is closed. The general purpose of notifications is to inform other objects of program
events so they can respond appropriately. But objects receiving notifications can react only after the event
has occurred. This is a significant difference from delegation. The delegate is given a chance to reject or
modify the operation proposed by the delegating object. Observing objects, on the other hand, cannot
directly affect an impending operation.

128.Where can you test Apple iPhone apps if you don’t have the device?

iOS Simulator can be used to test mobile applications. Xcode tool that comes along with iOS SDK
includes Xcode IDE as well as the iOS Simulator. Xcode also includes all required tools and frameworks
for building iOS apps. However, it is strongly recommended to test the app on the real device before
publishing it.

129.Which JSON framework is supported by iOS?

SBJson framework is supported by iOS. It is a JSON parser and generator for Objective?C. SBJson
provides flexible APIs and additional control that makes JSON handling easier.

130.What are the tools required to develop iOS applications?

iOS development requires Intel based Macintosh computer and iOS SDK.

131.Name the framework that is used to construct application’s user interface for iOS.

The UIKit framework is used to develop application’s user interface for iOS. UI kit framework provides
event handling, drawing model, windows, views, and controls specifically designed for a touch screen
interface.

132.What is C#?

C# (pronounced "C sharp") is a simple, modern, object oriented, and type safe programming language. It
will immediately be familiar to C and C++ programmers. C# combines the high productivity of Rapid
Application Development (RAD) languages.

133.What are the types of comment in C#?

There are 3 types of comments in C#.

  • Single line (//)
  • Multi (/* */)
  • Page/XML Comments (///).

134.What are the namespaces used in C#.NET?

Namespace is a logical grouping of class.

  • using System?
  • using System.Collections.Generic?
  • using System.Windows.Forms?

135.What are the characteristics of C#?

There are several characteristics of C# are:

  • Simple
  • Type safe
  • Flexible
  • Object oriented
  • JOBSMATE.COM
  • Compatible
  • Consistent
  • Interoperable
  • Modern

136.What are the different categories of inheritance?

Inheritance in Object Oriented Programming is of four types:

  • Single inheritance: Contains one base class and one derived class.
  • Hierarchical inheritance: Contains one base class and multiple derived classes of the same base class.
  • Multilevel inheritance: Contains a class derived from a derived class.
  • Multiple inheritances: Contains several base classes and a derived class.

137.Can you inherit multiple interfaces?

Yes. Multiple interfaces may be inherited in C#.

138.What is inheritance?

Inheritance is deriving the new class from the already existing one.

139.Define scope?

Scope refers to the region of code in which a variable may be accessed.

140.What is the difference between public, static and void?

Public: The keyword public is an access modifier that tells the C# compiler that the main method is
accessible by anyone

Static: The keyword static declares that the Main method is a global one and can be called without creating
an instance of the class. The compiler stores the address of the method as the entry point and uses this
information to begin execution before any objects are created.

Void: The keyword void is a type modifier that states that the Main method does not return any value.

Void: The keyword void is a type modifier that states that the Main method does not return any value.

141.What are the modifiers in C#?

  • Abstract
  • Sealed
  • Virtual
  • Const
  • Event
  • Extern
  • Override
  • Read-only
  • Static

142.What are the types of access modifiers in C#?

Access modifiers in C# are:

  • public
  • protect
  • private
  • internal
  • internal protect.

143.What is boxing and unboxing?

Implicit conversion of value type to reference type of a variable is known as BOXING, for example
integer to object type conversion. Conversion of reference type variable back to value type is called as
Unboxing.

144.What is object?

An object is an instance of a class. An object is created by using operator new. A class that creates an
object in memory will contain the information about the values and behaviors (or methods) of that specific
object.

145.Where are the types of arrays in C#?

  • Single-Dimensional
  • Multidimensional
  • Jagged arrays.

146.What is the difference between Object and Instance?

An instance of a user defined type is called an object. We can instantiate many objects from one class. An
object is an instance of a class.

147.Define destructors?

A destructor is called for a class object when that object passes out of scope or is explicitly deleted. A
destructors as the name implies is used to destroy the objects that have been created by a constructors. Like
a constructor, the destructor is a member function whose name is the same as the class name but is
precised by a tilde.

148.What is the use of enumerated data type?

An enumerated data type is another user defined type which provides a way for attaching names to
numbers thereby increasing comprehensibility of the code. The enum keyword automatically enumerates a
list of words by assigning those values 0, 1, 2, and so on.

149.Define Constructors?

A constructor is a member function with the same name as its class. The constructor is invoked whenever
an object of its associated class is created. It is called constructor because it constructs the values of data
members of the class.

150.What is encapsulation?

The wrapping up of data and functions into a single unit (called class) is known a encapsulation.
Encapsulation containing and hiding information about an object, such as internal data structures and code.

151.Does c# support multiple inheritance?

No, it’s impossible which accepts multi level inheritance.

152.What is ENUM

Enum are used to define constants.

153.What is a data set?

A Dataset is an in memory representation of data loaded from any data source.

154.What is the difference between private and public keyword?

Private: The private keyword is the default access level and most restrictive among all other access levels.
It gives least permission to a type or type member. A private member is accessible only within the body of
the class in which it is declared.

Public: The public keyword is most liberal among all access levels, with no restrictions to access what so
ever. A public member is accessible not only from within, but also from outside, and gives free access to
any member declared within the body or outside the body.

155.Define polymorphism?

Polymorphism means one name, multiple forms. It allows us to have more than one function with the same
name in a program. It allows us to have overloading of operators so that an operation can exhibit different
behaviors in different instances.

156.What is Jagged Arrays?

A jagged array is an array whose elements are arrays. The elements of a jagged array can be of different
dimensions and sizes. A jagged array is sometimes called an array–of–arrays.

157.What is an abstract base class?

An abstract class is a class that is designed to be specifically used as a base class. An abstract class
contains at least one pure virtual function.

158.How is method overriding different from method overloading?

When overriding a method, you change the behavior of the method for the derived class. Overloading a
method simply involves having another method with the same name within the class.

159.What is the difference between ref & out parameters?

An argument passed to a ref parameter must first be initialized. Compare this to an out parameter, whose
argument does not have to be explicitly initialized before being passed an out parameter.

160.What is the use of using statement in C#?

The using statement is used to obtain a resource, execute a statement, and then dispose of that resource.

161.What are the difference between Structure and Class?

  • Structures are value type and Classes are reference type
  • Structures can not have contractors or destructors.
  • Classes can have both contractors and destructors.
  • Structures do not support Inheritance, while Classes support Inheritance.

162.What is difference between Class And Interface?

Class is logical representation of object. It is collection of data and related sub procedures with definition.
Interface is also a class contain methods which is not having any definitions. Class does not support
multiple inheritance. But interface can support.

163.What is Delegates?

Delegates are a type safe, object-oriented implementation of function pointers and are used in many
situations where a component needs to call back to the component that is using it.

164.What is Authentication and Authorization?

Authentication is the process of identifying users. Authentication is identifying/validating the user against
the credentials (username and password). Authorization performs after authentication. Authorization is the
process of granting access to those users based on identity. Authorization allowing access of specific
resource to user.

165.What is a base class?

A class declaration may specify a base class by following the class name with a colon and the name of the
base class. omitting a base class specification is the same as deriving from type object.

166.Can “this” be used within a static method?

No ‘This’ cannot be used in a static method. As only static variables/methods can be used in a static
method.

167.What is difference between constants, read-only and, static ?

  • Constants : The value can’t be changed.
  • Read-only : The value will be initialized only once from the constructor of the class.
  • Static : Value can be initialized once.

168.What are the different types of statements supported in C#?

C# supports several different kinds of statements are

Block statements

Declaration statements

Expression statements

Selection statements

Iteration statements

Jump statements

Try catch statements

Checked and unchecked

Lock statement

169.What is an interface class?

It is an abstract class with public abstract methods all of which must be implemented in the inherited
classes.

170.What are value types and reference types?

Value types are stored in the Stack.

Examples : bolo, byte, chat, decimal, double, enema , float, into, long, byte, short, strut, unit, along, short.

Reference types are stored in the Heap.

Examples : class, delegate, interface, object, string.

171.What is the difference between string keyword and System.String class?

String keyword is an alias for Syste.String class. Therefore, System.String and string keyword are the
same, and you can use whichever naming convention you prefer. The String class provides many methods
for safely creating, manipulating, and comparing strings.

172.What are the two data types available in C#?

Value type
Reference type

173.What are the different types of Caching?

There are three types of Caching:

  • Output Caching: stores the responses from an asp.net page.
  • Fragment Caching: Only caches/stores the portion of page (User Control)
  • Data Caching: is Programmatic way to Cache objects for performance.

174.What is the difference between Custom Control and User Control?

Custom Controls are compiled code (Dlls), easier to use, difficult to create, and can be placed in toolbox.
Drag and Drop controls.

Attributes can be set visually at design time. Can be used by Multiple Applications (If Shared Dlls), Even if
Private can copy to bin directory of web application add reference and use. Normally designed to provide
common functionality independent of consuming Application.

User Controls are similar to those of ASP include files, easy to create, can not be placed in the toolbox and
dragged dropped from it. A User Control is shared among the single application files.

175.What is methods?

A method is a member that implements a computation or action that can be performed by an object or
class. Static methods are accessed through the class. Instance methods are accessed through instances of
the class.

176.What is fields?

A field is a variable that is associated with a class or with an instance of a class.

177.What is literals and their types?

Literals are value constants assigned to variables in a program. C# supports several types of literals are

  • Integer literals
  • Real literals
  • Boolean literals
  • Single character literals
  • String literals
  • Backslash character literals

178.What is the difference between value type and reference type?

Value types are stored on the stack and when a value of a variable is assigned to another variable.

Reference types are stored on the heap, and when an assignment between two reference variables occurs.

179.What are the features of c#?

C# is a simple and powerful programming language for writing enterprise edition applications. This is a
hybrid of C++ and VB. It retains many C++ features in the area statements, expressions, and operators and
incorporated the productivity of VB. C# helps the developers to easily build the web services that can be
used across the Internet through any language, on any platform.C# helps the developers accomplishing
with fewer lines of code that will lead to the fewer errors in the code. C# introduces the considerable
improvement and innovations in areas such as type safety, versioning. events and garbage collections.

180.What are the types of errors?

  • Syntax error
  • Logic error
  • Runtime error

181.What is the difference between break and continue statement?

The break statement is used to terminate the current enclosing loop or conditional statements in which it
appears. We have already used the break statement to come out of switch statements. The continue
statement is used to alter the sequence of execution. Instead of coming out of the loop like the break
statement did, the continue statement stops the current iteration and simply returns control back to the top
of the loop.

182.Define namespace?

The namespace are known as containers which will be used to organize the hierarchical set of .NET
classes.

183.What is a code group?

A code group is a set of assemblies that share a security context.

184.What are sealed classes in C#?

The sealed modifier is used to prevent derivation from a class. A compile time error occurs if a sealed class
is specified as the base class of another class.

185.What is the difference between static and instance methods?

A method declared with a static modifier is a static method. A static method does not operate on a specific
instance and can only access static members. A method declared without a static modifier is an instance
method. An instance method operates on a specific instance and can access both static and instance
members. The instance on which an instance method was invoked can be explicitly accessed as this. It is
an error to refer to this in a static method.

186.What are the different types of variables in C#?

Different types of variables used in C# are :

  • static variables
  • instance variable
  • value parameters
  • reference parameters
  • array elements
  • output parameters
  • local variables.

187.What is meant by method overloading?

Method overloading permits multiple methods in the same class to have the same name as long as they
have unique signatures. When compiling an invocation of an overloaded method, the compiler uses
overload resolution to determine the specific method to invoke.

188.What is parameters?

Parameters are used to pass values or variable references to methods. The parameters of a method get their
actual values from the arguments that are specified when the method is invoked. There are four kinds of
parameters: value parameters, reference parameters, output parameters, and parameter arrays.

189.Is C# is object oriented?

Yes, C# is an OO language in the tradition of Java and C++.

190.What is the difference between Array and Array list?

An array is a collection of the same type. The size of the array is fixed in its declaration. A linked list is
similar to an array but it doesn’t have a limited size.

191.What are the special operators in C#?

C# supports the following special operators.

is (relational operator)

as (relational operator)

typeof (type operator)

sizeof (size operator)

new (object creator)

.dot (member access operator)

checked (overflow checking)

unchecked (prevention of overflow checking)

192.What is meant by operators in c#?

An operator is a member that defines the meaning of applying a particular expression operator to instances
of a class. Three kinds of operators can be defined: unary operators, binary operators, and conversion
operators. All operators must be declared as public and static.

193.What is a parameterized type?

A parameterized type is a type that is parameterized over another value or type.

194.What are the features of abstract class?

An abstract class cannot be instantiated, and it is an error to use the new operator on an abstract class. An
abstract class is permitted (but not required) to contain abstract methods and accessors. An abstract class
cannot be scaled.

195.What is the use of abstract keyword?

The modifier abstract is a keyword used with a class, to indicate that this class cannot itself have direct
instances or objects, and it is intended to be only a 'base' class to other classes.

196.What is the use of goto statement?

The goto statement is also included in the C# language. This goto can be used to jump from inside a loop to
outside. But jumping from outside to inside a loop is not allowed.

197.What is the difference between console and window application?

A console application, which is designed to run at the command line with no user interface. A Windows
application, which is designed to run on a user’s desktop and has a user interface.

198.What is the use of return statement?

The return statement is associated with procedures (methods or functions). On executing the return
statement, the system passes the control from the called procedure to the calling procedure. This return
statement is used for two purposes :

to return immediately to the caller of the currently executed code

to return some value to the caller of the currently executed code.

199.What is the difference between Array and Linked List?

Array is a simple sequence of numbers which are not concerned about each others positions. they are
independent of each others positions. adding, removing or modifying any array element is very easy.
Compared to arrays ,linked list is a complicated sequence of numbers.

200.Does C# have a throws clause?

No, unlike Java, C# does not require the developer to specify the exceptions that a method can throw.

201.Does C# support a variable number of arguments?

Yes, using the params keyword. The arguments are specified as a list of arguments of a specific type.

202.Can you override private virtual methods?

No, private methods are not accessible outside the class.

203.What is a multi cast delegates?

Each delegate object holds reference to a single method. However, it is possible for a delegate object to
hold references of and invoke multiple methods. Such delegate objects are called multicast delegates or
combinable delegates.

204.Which is an exclusive feature of C#?

Xml documentation.

205.Is using of exceptions in C# recommended?

Yes, exceptions are the recommended error handling mechanism in .NET Framework.

206.What does a break statement do in switch statements?

The break statement terminates the loop in which it exists. It also changes the flow of the execution of a
program. In switch statements, the break statement is used at the end of a case statement. The break
statement is mandatory in C# and it avoids the fall through of one case statement to another.

207.Is C# object oriented?

Yes, C# is an OO language in the tradition of java and C++.

208.What is smart navigation?

The cursor position is maintained when the page gets refreshed due to the server side validation and the
page gets refreshed.

209.What is the difference between CONST and READONLY?

Both are meant for constant values. A const field can only be initialized at the declaration of the field. A
read-only field can be initialized either at the declaration or.

210.Does C# have a throws clause?

No, unlike Java, C# does not require (or even allow) the developer to specify the exceptions that a method
can throw.

211.What are the different ways a method can be overloaded?

Different parameter data types, different number of parameters, different order of parameters.

212.Do events have return type?

No, events do not have return type.

213.What is event?

An event is an action performed based on another method of the program. An event is a delegate type dass
member that is used by an object or a class to provide a notification to other objects that an event has
occurred. An event can be declared with the help of the event keyword.

214.What is an identifier?

Identifiers are nothing but names given to various entities uniquely identified in a program.

215.What are the different types of literals in C#?

Boolean literals: True and False are literals of the Boolean type that map to the true and false state,
respectively

Integer literals: Used to write values of types Int, ulnt, long, and ulong.

Real literals: Used to write values of types float, double, and dedmal.

Character literals: Represents a single character and usually consists of a character in quotes, such as 'a'.

String literals: C# supports two types of string literals, regular string literal and verbatim string literals. A
regular string literal consists of zero or more characters enclosed in double quotes, such as "116110". A
verbatim string literal consists of an @ character followed by a double–quote character, such as ©"hello".

The Null literal: Represents the null–type.

216.What is meant by data encapsulation?

Data encapsulation, also referred to as data hiding, is the mechanism whereby the implementation details of
a class are kept hidden from the user. The user can only perform a restricted set of operations on the hidden
members of the class by executing special functions called methods.

217.Can you override private virtual methods?

No. Private methods are not accessible outside the class.

218.What is the main difference between a sub procedure and a function

Sub procedures do not return a value, while functions do.

219.How does C# differ from C++?

C# does not support #include statement. It uses only using statement. In C# , class definition does not use a
semicolon at the end. C# does not support multiple code inheritance. Casting in C# is much safer than in
c++. In C# switch can also be used on string values Command line parameters array behave differently in
C# as compared to C++.

220.What is nested class?

A Nested classes are classes within classes. A nested class is any class whose declaration occurs within the
body of another class or interface.

221.Can you have parameters for static constructors?

No, static constructors cannot have parameters.

222.Is String is Value Type or Reference Type in C#?

String is an object(Reference Type).

223.Does C# provide copy constructor?

No, C# does not provide copy constructor.

224.Can you create an instance of an interface?

No, you cannot create an instance of an interface.

225.Can an Interface contain fields?

No, an Interface cannot contain fields.

226.Can a class have static constructor?

Yes, a class can have static constructor. Static constructors are called automatically, immediately before
any static fields are accessed, and are generally used to initialize static class members. It is called
automatically before the first instance is created or any static members are referenced. Static constructors
are called before instance constructors.