– ‘ C ‘ –

Q: – Explain about storage of union elements. 

The key point about storage of union elements is that Union elements are use to share common memory space.

Q: – What is a memory leak?

Memory leak is that when memory is allocated but its not released because of an application consume memory reducing the available memory for other applications and causing the system to page virtual memory to the hard drive showing the application or crashing the application. When the computer memory resource limits are reached.

Q: – Is C is platform dependent or independent?how and why?

Major issue behind designing C language is that it is a small,portable programming language. It is used to implement an operating system.In past time C is a powerful tool for writing all types of program and has mechanism to achieve all most programming goals.So, we can say that C is platform dependent.

Q: – What are the stream files?

We can open file in C with using stream files.which are identified with a pointer to a FILE structure, or as low-level files, which are identified with an integer handle.

We can open stream files with using one of the following functions.

fopen(): Opens the specified file with the specified mode
freopen(): Closes the file specified, then opens a new file as specified
fdopen(): Opens a duplicate stream file for an already open low-level file

Q: – How the processor registers can be used in C? 

using keyword register we can use the process register in C.Basically process register is used to store variables those i want to access frequently.if these registers are not used in any other program,then those registers we used to allocate memory these variables.

Q: – How to access or modify the constt variable in C ?

We can not modify the constant variable.

Q: – Why n++ executes faster than n+1?

n++ executes faster than n+1 because n++ want only one instruction for execution where n+1 want more one instruction for execution.

Q: – What is the difference between the Heap and the Stack?

The main difference b/n the Heap and the Stack are given below:

– In stack we create object temporary where programmer used to reserve allocation.’
– stack not have automatic garbage collection where as heap have automatic garbage collection.

Q: – What is the Double LinkedList?

Double Linked List is that each data item in the list can point both side(next or previous)data item.It is not specific type means it may be of stack or queue.This is use to increase the performance of program.It is also called as Two-way Linked List or Symmetrically Linked list.

Q: – What are the advantages of high-level programming languages?

Readability, maintainability, and portability

Q: – Why is the main() function needed in a program?

The execution of a C program starts and ends with the main() function. Without the main() function, the computer does not know where to start to run a program.

Q: – What does the #include directive do?

The #include directive is used to include header files that contain the declarations to the functions used in your C program. In other words, the #include directive tells the C preprocessor to look into the include path to find the specified header file.

Q: – Why do you need a linker?

After compiling, some function code may still be missing in the object file of a program. A linker must then be used to link the object file to the C standard library or other user-generated libraries and include the missing function code so that an executable file can be created.

Q: – What is the difference between a constant and a variable?

The major difference is that the value of a constant cannot be changed, whereas the value of a variable can. You can assign different values to a variable whenever it’s necessary in your C program.

Q: – Why do you need a statement block?

Many C keywords can only control one statement. A statement block provides a way to put more than one statement together, and put the statement block under the control of a C keyword. Then, the statement block is treated as a single statement.

Q: – Which arithmetic operators have a higher precedence?

Among the five arithmetic operators, the multiplication, division, and remainder operators have a higher precedence than the addition and subtraction operators.

Q: – How many parts does a function normally have?

A function normally has six parts: the function type, the function name, the arguments, the opening brace, the function body, and the closing brace.

Q: – How can you declare two character variables?

There are two ways to do the declaration. The first one is

…char variable-name1, variable-name2;

The second one is

char variable-name1;
char variable-name2;

Q: – What are %c, %d, and %f?

These are format specifiers. %c is used to obtain the character format; %d is for the integer format; %f is for the floating-point format. %c, %d, and %f are often used with C functions such as printf().

Q: – What are the main differences between the int data type (integer) and the float data type (floating-point)?

First, an integer does not contain any fraction parts, but a floating-point number does. A floating-point number must have a decimal point. In C, the float data type takes more bits than the int data type. In other words, the float data type has a larger range of numeric values than the int data type.

Q: – What are stdin, stdout, and stderr?

In C, a file is treated as a series of bytes that is called file stream. stdin, stdout, and stderr are all pre-opened file streams. stdin is the standard input for reading; stdout is the standard output for writing; stderr is the standard error for outputting error messages.

Q: – What value is yielded by a relational expression?

A relational expression evaluates to either 0 or 1. If the relation indicated by a relational operator in an expression is true, the expression evaluates to 1; otherwise, the expression evaluates to 0.

Q: – Is the unary minus operator (-) the same as the subtraction operator (-)?

No, they are not the same, although the two operators share the same symbol. The meaning of the symbol is determined by the context in which it appears. The unary minus operator is used to change the sign of a numeric value. In other words, the unary minus operator yields the negation of the value. The subtraction operator is an arithmetic operator that performs a subtraction between its two operands.

Q: – Why do we need the sizeof operator?

The sizeof operator can be used to measure the sizes of all data types defined in C. When you write a portable C program that needs to know the size of an integer variable, it’s a bad idea to hard-code the size based on the machine you are currently using. The better way to tell the program the size of the variable is to use the sizeof operator, which yields the size of the integer variable at runtime.

Q: – What can the %lu format specifier do?

The %lu format specifier can be used in a printf() string to convert the corresponding argument to the unsigned long int data type. In addition, the %lu format specifier is equivalent to %Lu.

Q: – What are the left and right values?

The left value is the address of a variable, and the right value is the content stored in the memory location of a variable.

Q: – How can you obtain the address of a variable?

By using the address-of operator, &.

Q: – Can a null pointer point to valid data?

No. A null pointer cannot point to valid data. This is because the value contained by a null pointer has been set to 0.

Q: – What can the null character do?

The null character (‘’) in C can be used to mark the end of a string.

Q: – Can a global variable be hidden by a local variable with block scope?

Yes

Q: – Why do we need function prototypes?

With the help of a function prototype, the compiler can automatically perform type checking on the definition of the function, which saves you time in debugging the program.

Q: – Can a function return a pointer?

Yes

Q: – Why do you need to use arrays of pointers?

It is convenient to use an array of pointers to point to a set of character strings so that you can access any one of the strings referenced by a corresponding pointer in the array.

Q: – What does it mean if the malloc() function returns a null pointer?

If the malloc() function returns a null pointer, it means the function failed to allocate a block of memory whose size is specified by the argument passed to the function.

Q: – What are the differences between the calloc() and malloc() functions?

The calloc() function takes two arguments, while the malloc() function takes only one. The second difference is that the calloc() function initializes the allocated memory space to 0, whereas there is no such guarantee made by the malloc() function.

Q: – Is the free() function necessary?

Yes. The free() function is very necessary, and you should use it to free up allocated memory blocks as soon as you don’t need them.

Q: – What can you do with the enum data type?

The enum data type can be used to declare names that represent integer constants.

Q: – Why do you need to use the typedef keyword?

By using the typedef keyword, you can define your own names to represent the data types in C.

Q: – Can you redirect a standard stream to a disk file?

Yes. With the help of the freopen() function, you can redirect a standard stream and associate the stream with a disk file.

Q: – Is the C preprocessor part of the C compiler?

No

Q: – How do you remove a macro name?

By using the #undef directive with a macro name, that macro name can be removed, or “undefined.”

Q: – Why do you need the #endif directive?

The #endif directive is used with an #if, #ifdef, or #ifndef directives because statements under the control of a conditional preprocessor directive are not enclosed in braces ({ and }). Therefore, #endif must be used to mark the end of the block of statements.

Q: – Can the conditional expression following the #if directive be an arithmetic expression?

Yes

Q: – What is the difference b/n run time binding and compile time binding?

When the address of functions are determined a run time than it is called run time or dynamic binding or late binding. While when the addresses of functions are determined a compile time than it is called compile time or static binding or early binding.

Q: – Why do you need the #endif directive?

The key difference b/n linker and linkage is that linker is used to change an object code into an executable code by linking together the necessary build in functions. Place where we declare the variable in a program is called the linkage of variable.

Q: – What is the Double LinkedList?

Double Linked List is that each data item in the list can point both side(next or previous)data item.

Q: – Can we write a program with out using main() function?

No

Q: – Explain “method”?

A Method is a programmed procedure. It is defined as part of a class also included in any object of that class. Class can have more than one methods. It can be re-used in multiple objects.

Q: – What is the Double LinkedList?

Double Linked List is that each data item in the list can point both side(next or previous)data item.

Q: – Can we write a program with out using main() function?

No

Q: – Explain “method”?

A Method is a programmed procedure. It is defined as part of a class also included in any object of that class. Class can have more than one methods. It can be re-used in multiple objects.

Q: – Write a programme to display number from the bellow string?

char *ptr=”HELLO57hai”

#include<stdio.h>

int main()
{
char *ptr=”HELLO57hai”;
while(*ptr)
{
if(*ptr<‘A’)
printf(“%c”,*ptr);
ptr++;
}
}

Q: – what are compilation process or steps?

prepocessor->compiler->assembler->linkEditor==Executable code

Q: – What is the output of the bellow program?

segmentation fault.because we are trying to read/assign character into const string.

#include<stdio.h>
main()
{
char *ptr=”HELLO”;
ptr[0]=’A’;
printf(“%s”,ptr);
}

Q: – There are numbers range from 1 to n randamly stored in the array and one number is missed in that array.write a program to find out missing number?

int missing_number(int a[],int n)
{
int Total,i;
Total=(n+1)*(n+2)/2;
for(i=0;i<n;i++)
Total -=a[i];
return Total;
}

Q: – What is the output of this Programme?

#include<stdio.h>
int main()
{
int x[]={1,3,2,4,6};
int *ptr,y;
ptr=x+4;
y=ptr-x;
printf(“%d\n”,y);
}

Q: – How do you find middle element in the single linked list by traversing only one time from first to last?

we can findout middle element by taking two pointers.increment twice ptr1 while incrementing the ptr2 once ,so when ptr1 reaches to end of the node in the list,ptr2 will be pointing to middle element in the list. so we just return adress of middle element.
struct person*find_middle(struct person **listhead)
{
struct person *ptr1,*ptr2;
ptr1=ptr2=*listhead;
int i=0;
while(ptr1->link!=NULL)
{
if(i==0)
{
ptr1=ptr1->link;
i=1;
}
else if(i==1)
{
ptr1=ptr1->link;
ptr2=ptr2->link;
i=0;

}
}
return ptr2;
}

Q: – What are “<<” and “>>” in C language. what is the output of the bellow code program?

#include<stdio.h>
int main()
{
int x=0x00AA;
int y=0x0055;
int z;
z=x<<8 + y>>8;
printf(“%d\n”,z);
}

Answer:

In C language <<(Left shift operator) and >>(Right shift operator) are called Bitwise operators and used to work on bits.
Z value is 4194304 for the above program.

Q: – What is Void pointer? can we perform arithimetic operations on void pointers?why? give one example?

void pointer is one kind of pointer ,it supports to hold data of all datatypes(like int,char,float etc).it’s also called generic pointer.we can’t perform arithimatic operations on void pointer because compiler doesn’t know the type of data to increment.

Ex:

#include<stdio.h>
int main()
{
int a[]={100,200};
void *ptr;
ptr=a;
ptr++;
printf(“%d\n”,*ptr); //here error occur.
}

Q: – What is the output of this program?

#include<stdio.h>
char *myfun(char *p)
{
p+=3;
return p;
}
int main()
{
int *p;
int *q;
p=”HELLO”;
q=myfun(p);
printf(“%s”,q);
}

Answer: LO.

Q: – Write a program to reverse a string with out using any array?

#include<stdio.h>
int main()
{
char *str=”Mahesh”;
char *ptr=str+strlen(str);
while(ptr>=str)
{
printf(“%c”,*ptr);
ptr–;
}
}

 

Q: – What is the output of this programe?

#include<stdio.h>
void Allocate(char *str, int size)
{
str =(char *)malloc(size);
}
int main()
{
char *str;
Allocate(str, 20);
strcpy(str, “HCL”);
strcat(str, “Technologies”);
printf(“%s\n”,str);
}

Answer:Run time error(segmentation fault).

Reason: in function Allocate, we have allocated memory by using malloc function and assigned adress of that block to local pointer str. when control returns from that function the pointer (str) dies.so it will not affect in the main function. in main function,we are trying to read memory by using printf statement. so run time error occur.

Q: – What is the output of this programe?

#include<stdio.h>
main()
{
char *ptr =”HCL Technologies”;
(*ptr)++;
printf(“%s\n”,ptr);
ptr++;
printf(“%s\n”,ptr);
}

Answer:segmentation fault.because we are trying to modify the const string.

Q: – What is the output of this programe?

#include<stdio.h>
void show()
{
static int i=1;
printf(“%d\n”,i++);
}

int main()
{
show();show();show();
}

Answer:1 2 3. static varibles values remain in function calls.if i(variable) in function show() islocal variable the out put would be 1 1 1.

 

Advertisements

One thought on “– ‘ C ‘ –

  1. The cities are new and too busy that this option is not suitable for the people going to some place for a
    visit or on a temporary basis. Such kinds of services are beneficial for families visiting London.
    Otherwise, stay while in the contractual limit.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s