All java c# .net servlet jdbc c sqlserver android javascript php wcf clearcase angularjs 2

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.

It indicated the end of array character. It is also referred as null character .'\0' is a "null character". It's used to terminate strings in C and some portions of C ++.
It indicated the end of array character.It is also referred as null character.

What will be the output of following program?

Answer is B After i reaches 32767, i++ will make i as -32768. Hence it will never become greater than 32768 and continuos infinitely.

Input/output function prototypes and macros are defined in which header file?

stdio.h, which stands for "standard input/output header", is the header in the C standard library that contains macro definitions, constants, and declarations of functions and types used for various standard input and output operations.

What will be the output?

&a[i] = &a + i; Hence, &a[3] - &a[1] = (&a + 3) - (&a + 1) = 2.
In this code format '%d' expects argument of type 'int', but argument 2 has type 'long int' printf("%d",&a[3]-&a[1]); return type default to 'int'

What is the difference between strdup and strcpy?

Both copy a string. strcpy wants a buffer to copy into. strdup allocates a buffer using malloc().
Unlike strcpy(), strdup() is not specified by ANSI.

strcpy(ptr2, ptr1) is equivalent to while(*ptr2++ = *ptr1++)

where as strdup is equivalent to

ptr2 = malloc(strlen(ptr1)+1);

So if you want the string which you have copied to be used in another function (as it is created in heap section) you can use strdup, else strcpy is enough.

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 “x++” 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?.

If evaluating an expression results in a change in the state of the execution environment then expression has some side effect. Sequence point is a point in time at which all side effects seen so far are guaranteed to be complete.

The order of evaluation of operands and subexpressions of individual expressions, and the order in which the side effects take place, is unspecified.

  1. int a = b++ + c++; // Can't say whether b++ or c++ is evaluated first.

Also, between two sequence points a variable must not be modified more than once.

  1. int j = i++ + i++; // invalid!

Since C++11, sequence points have been replaced by sequenced before, sequenced after, unsequenced and indeterminately sequenced.

What is friend function?

The function declaration should be preceded by the keyword friend.The function definitions does not use either the keyword or the scope operator ::. The functions that are declared with the keyword friend as friend function.Thus, a friend function is an ordinary function or a member of another class.

A friend function of a class is defined outside that class' scope but it has the right to access all private and protected members of the class. Even though the prototypes for friend functions appear in the class definition, friends are not member functions.

Private data members cannot be accessed from outside the class. However, situations arise where two classes need to share a particular function. For such situations, C++ introduces friend functions. These are functions that can be made friendly with both the classes, thus allowing these functions to have an access to the private data of these classes.

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.

This c program generates pseudo random numbers using rand and random function(Turbo C compiler only). As the random numbers are generated by an algorithm used in a function they are pseudo random, this is the reason why pseudo word is used. Function rand() returns a pseudo random number between 0 and RAND_MAX. RAND_MAX is a constant which is platform dependent and equals the maximum value returned by rand function.
#include <stdio.h>
#include <stdlib.h>
int main() {
  int c, n;
  printf("Ten random numbers in [1,100]\n");
  for (c = 1; c <= 10; c++) {
    n = rand() % 100 + 1;
    printf("%d\n", n);
  return 0;

If you return this program you will get same set of numbers. To get different numbers every time you can use: srand(unsigned int seed) function, here seed is an unsigned integer. So you will need a different value of seed every time you run the program for that you can use current time which will always be different so you will get a different set of numbers. By default seed = 1 if you do not use srand function.

The rand() function is the simplest of C’s random-number functions. It requires the stdlib.h header file, and it coughs up an int value that’s supposedly random. 

#include <time.h>
#include <stdlib.h>

int r = rand();

What is wild pointer in c?

A pointer in c which has not been initialized is known as wild pointer.


What will be output of following c program?

int main(){
int *ptr;
return 0;

Output: Any address
Garbage value

Here ptr is wild pointer because it has not been initialized. There is difference between the NULL pointer and wild pointer. Null pointer points the base address of segment while wild pointer doesn’t point any specific memory location.

Uninitialized pointers are known as wild pointers because they point to some arbitrary memory location and may cause a program to crash or behave badly. Wild pointers are created by omitting necessary initialization prior to first use. Thus, strictly speaking, every pointer in programming languages which do not enforce initialization begins as a wild pointer.

Wild pointers are created by omitting necessary initialization prior to first use. Thus, strictly speaking, every pointer in programming languages which do not enforce initialization begins as a wild pointer. This most often occurs due to jumping over the initialization, not by omitting it. Most compilers are able to warn about this.

What is the difference between local variable and global variable in C?

Local variable: A variable which is declared inside function or block is known as local variable.

Global variable: A variable which is declared outside function or block is known as global variable.

Global Variable-

Global Variable Are That Variable Which is Define At The Top Of The Programmer (After Header Files)

We Can Access From Any Where.

There Initial Values int=0, float=0.000000, char- “Blank Space(Non-Printable Char)”.

Scope[Availability] is Through Out Of The Program.

Life-Time[Active in Memory] is Until Total Program is Executed.

The Are Stored in Data Segment Area,Which is Public Area. Hence They Are Also Called as Public Variables.

Local Variable-

The Variables That Are Declared Inside A Function Are Called Local Variables.

The Are Stored in Stack

There Initial Values Are Garbage.

Scope[Availability] is until that function or block are executed.

Life-Time[Active in Memory] is Until That Function is Executed.

LOCAL VARIABLE- when you declare any variable inside functions like any {main function} or {user defined function} the scope of that variable is in inside only that function you can not use that variable in any other function. scope of that variable is limited inside that function only. but in GLOBAL VARIABLE- when you declare global variable outside main function. you can use that variable through out the entire can use that variable in any function.

Local variable has a limited scope within function only in which it is declared.


Global variable does’t have limited scope it can be access though out the program.