0% found this document useful (0 votes)
75 views

C Inter

The document discusses various C programming concepts in response to questions. Key points include: 1. The basic compilation stages in C are source code, preprocessing, compilation, assembly, linking, and loading. 2. Declarations introduce identifiers and their types, while definitions instantiate the identifiers needed for linking. 3. Structures allow grouping of different data types into a single type. Members can be accessed using dot or arrow operators. 4. The dot operator accesses members from a structure variable, while the arrow operator accesses members from a structure pointer. 5. The volatile qualifier tells the compiler a variable's value may change without compiler-visible actions.

Uploaded by

yaseen22
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
75 views

C Inter

The document discusses various C programming concepts in response to questions. Key points include: 1. The basic compilation stages in C are source code, preprocessing, compilation, assembly, linking, and loading. 2. Declarations introduce identifiers and their types, while definitions instantiate the identifiers needed for linking. 3. Structures allow grouping of different data types into a single type. Members can be accessed using dot or arrow operators. 4. The dot operator accesses members from a structure variable, while the arrow operator accesses members from a structure pointer. 5. The volatile qualifier tells the compiler a variable's value may change without compiler-visible actions.

Uploaded by

yaseen22
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 32

ARI

1.Explain about compilation stages in C?


A:  Basic compilation stages in normal C are Source code,Preprocessing,
Compiler,Assembler,Linker, Loader.
2.What is declaration & definition ?
A: A declaration introduces an identifier and describes its type, be it a
type, object, or function. A declaration is what the compiler needs to
accept references to that identifier. These are declarations:
Extern int bar;
Extern int g(int,int);

A definition actually instantiates/implements this identifier. It's what


the linker needs in order to link references to those entities. These are
definitions corresponding to the above declarations:
Int bar;
Int

g(int lhs,int rhs) {return lhs*rhs;}

3.What is a Structure & how to access the members?


A: A structure is a user defined data type in C/C++. A structure creates a
data type that can be used to group items of possibly different types
into a single type.
We cannot access members of a structure directly in any expression by
specifying their name alone.There are two ways to access structure
members:
Using Member Access Operator(.) or Dot Operator
structure_variable.member_name
Using Member Structure Pointer Operator or Arrow Operator(->)
structure_pointer->member_name;
4.Wht is the difference between “ . ” and “ -> ” in structures?
“.” Operator used to access the structure members from structure
variable.
“->” Operator used to access the structure members from structure
pointer.

5.What is Volatile keyword? Have you used in your projects?


A: volatile is a qualifier that is applied to a variable when it is declared. It tells the
compiler that the value of the variable may change at any time-without any
action being taken by the code the compiler finds nearby. The implications of this
are quite serious.

6.What are the storage class? Explain.


A: Storage Classes are used to describe about the features of a variable/function.
These features basically include the scope, visibility and life-time which help us to
trace the existence of a particular variable during the runtime of a program.
The following storage classes are most oftenly used in C programming,

1. Automatic variables
2. External variables
3. Static variables
4. Register variables
7.What is the difference between structures & unions?

8.what is the difference between malloc&calloc ?


A:
Differences between malloc and calloc
Malloc Calloc

The name malloc stands for memory The name calloc stands for contiguous


allocation. allocation.
void *malloc(size_t n) returns a void *calloc(size_t n, size_t
pointer to n bytes of uninitialized size)returns a pointer to enough free
storage, or NULL if the request cannot space for an array of n objects of the
be satisfied. If the space assigned specified size, or NULL if the request
by malloc() is overrun, the results are cannot be satisfied. The storage is
undefined. initialized to zero.
malloc() takes one argument that calloc() take two arguments those
is, number of bytes. are: number of blocks and size of each
block.
syntax of malloc(): syntax of calloc():
void *malloc(size_t n); void *calloc(size_t n, size_t size);
Allocates n bytes of memory. If the Allocates a contiguous block of
allocation succeeds, a void pointer to memory large enough to
the allocated memory is returned. hold n elements of sizebytes each.
Otherwise NULL is returned. The allocated region is initialized to
zero.
malloc is faster than calloc. calloc takes little longer than malloc
because of the extra step of
initializing the allocated memory by
zero. However, in practice the
difference in speed is very tiny and
not recognizable.

9.what is memory leak & Dangling pointer?


A: Memory Leak:In a program a memory leak is said to have occurred if a
dynamically allotted memory is not deleted or freed and there is no way the
program can again access to the same memory location. Lets look at an example
to clearly understand how memory leak occurs.

Dangling Pointer:Dangling pointer is a situation which occurs when a programmer


tries to access a memory location through the variable/pointer when the memory
is already freed. Suppose if a programmer allocates a memory and store its
address in a pointer. If the memory allotted is freed and if the programmer
continues to refer to that memory location through the pointer then it is a case
of dangling pointer. Generally this situation will lead to run time error or
"Segmentation Fault".

10. Here some code Int a , b, c;


a=3;b=5;
c=a+b;
these four lines where will be stored in memory?
ARI
// 1.Brief discussions about storage class? (REPEATED)
2.Main difference between Static and Extern?
A:
Static Variable Extern Variable
1.Declared inside a function/block 1.Declared
Keyword - static outside all functions/blocks
2.Syntax - static datatype variable- Keyword- extern
name; 2.Syntax – extern datatype
3.Storage - static memory variable-name;
4.Default value - zero 3.Storage - static memory
5.Scope - accessible only to that 4.Default value - zero
particular function/block where it is 5.Scope - accessible to all the
defined functions/blocks of the program
6.Lifetime - entire program 6.Lifetime - entire program

3.Types of pointers and its use?


A:A pointer is a variable whose value is the address of another variable, i.e.,
direct address of the memory location. Like any variable or constant, you must
declare a pointer before using it to store any variable address. The general form
of a pointer variable declaration is :
type *var-name;

1.NULL Pointer
2.Dangling Pointer
3.Generic Pointers
4.Wild Pointer
5.Complex Pointers
6.Near Pointer
7.Far Pointer
8. Huge Pointers
NULL Pointer :Literal meaning of NULL pointer is a pointer which is pointing to
nothing. NULL pointer points the base address of segment. Examples of NULL
pointer

int *ptr=(char *)0;


float *ptr=(float *)0;
char *ptr=(char *)0;
double *ptr=(double *)0;
char *ptr=’’;
int *ptr=NULL;

NULL is macro constant which has been defined in the heard file as :
#define NULL 0

Dangling pointer :If any pointer is pointing the memory address of any variable
but after some variable has deleted from that memory location while pointer is
still pointing such memory location. Such pointer is known as dangling pointer
and this problem is known as dangling pointer problem.

Generic pointer :void pointer in c is known as generic pointer. Literal meaning of


generic pointer is a pointer which can point type of data.Example:
void *ptr;Here ptr is generic pointer.

We cannot dereference generic pointer. We can find the size of generic pointer
using sizeof operator. Generic pointer can hold any type of pointers like char
pointer, struct pointer, array of pointer etc without any typecasting.

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

Complex pointer :

Pointer to function
Pointer to array
Pointer to array of integer
Pointer to array of function
Pointer to array of character
Pointer to array of structure
Pointer to array of union
Pointer to array of array
Pointer to two dimensional array
Pointer to three dimensional array
Pointer to array of string
Pointer to array of pointer to string
Pointer to structure
Pointer to union
Multilevel pointers

In TURBO C there are three types of pointers. TURBO C works under DOS
operating system which is based on 8085 microprocessor.

1. Near pointer: The pointer which can points only 64KB data segment or
segment number 8 is known as near pointer.

2. Far pointer: The pointer which can point or access whole the residence
memory of RAM i.e. which can access all 16 segments is known as far pointer.

3. Huge pointer:The pointer which can point or access whole the residence
memory of RAM i.e. which can access all the 16 segments is known as huge
pointer.

http://www.emblogic.com/blog/12/what-are-the-different-types-of-c-pointers/

4.What is function pointer and explanation?


A:Concept of Pointer to a function known as function pointer in C.
function_return_type(*Pointer_name)(function argument list)
For example: double  (*p2f)(double,char).

Here double is a return type of function, p2f is name of the function pointer
a00000000000000000000nd (double, char) is an argument list of this function.
Which m0eans the first argument of this function is of double type and the
second argument is char type.
https://beginnersbook.com/2014/01/c-function-pointers/

5.Find biggest number without using array?

A:  #include<stdio.h>
    int main(){
                   int n, s1, s2, z;
                   printf(" How many Integer numbers : ");
scanf("%d", &n);
                   z=n;
                   if(n>0){
                   printf("\n Enter the First number : ");
                   scanf("%d", &s1);
                   n--;
                   if(n>0){
                   for(;n>=1; n--){
                   printf("\n Enter the next number : ");
                   scanf("%d", &s2);
                   if(s1<s2)
                   s1=s2;
                   }
                   }
                   }
    printf("\n The Largest of %d numbers is %d", z, s1);
    return(0);
  }

O/P: How many Integer numbers : 3


                       Enter the First number : 47
                       Enter the next number : 43
                       Enter the next number : 87
The Largest of 3 numbers is 87

//6.Structures and unions?


//7.explain about malloc?
ROBERT BOSCH
1.Explain about preprocessor stage?(with examples)
A:The first stage of compilation is called preprocessing. This phase includes:
 Removal of Comments
 Expansion of Macros
 Expansion of the included files.
https://www.calleerlandsson.com/posts/the-four-stages-of-compiling-a-c-
program/

// 2.What is the difference between static and extern? (REPEATED)


3. void( )
{
Void( );
}
What is the output of this code?
4.What is the difference between c &c++ ?
A:
Difference between C and C++
C C++

C was developed by Dennis Ritchie between C++ was developed by Bjarne


1969 and 1973 at AT&T Bell Labs. Stroustrup in 1979 with C++'s
predecessor "C with Classes".

When compared to C++, C is a subset of C+ C++ is a superset of C. C++ can run


+. most of C code while C cannot run C++
code.
C supports procedural programming C++ supports both procedural and
paradigm for code development. object oriented programming
paradigms; therefore C++ is also
called a hybrid language.

C does not support object oriented Being an object oriented


programming; therefore it has no support programming language C++ supports
for polymorphism, encapsulation, and polymorphism, encapsulation, and
inheritance. inheritance.

In C (because it is a procedural In C++ (when it is used as object


programming language), data and functions oriented programming language),
are separate and free entities. data and functions are encapsulated
together in form of an object. For
creating objects class provides a
blueprint of structure of the object.

In C, data are free entities and can be In C++, Encapsulation hides the data
manipulated by outside code. This is to ensure that data structures and
because C does not support information operators are used as intended.
hiding.

C, being a procedural programming, it is a While, C++, being an object oriented


function driven language. programming, it is an object driven
language.

C does not support function and operator C++ supports both function and
overloading. operator overloading.

C does not allow functions to be defined In C++, functions can be used inside a
inside structures. structure.

C does not have namespace feature. C++ uses NAMESPACE which avoid
name collisions.
A namespace is a declarative region
that provides a scope to the
identifiers (the names of types,
functions, variables, etc) inside it.
Namespaces are used to organize
code into logical groups and to
prevent name collisions that can occur
especially when your code base
includes multiple libraries. All
identifiers at namespace scope are
visible to one another without
qualification. Identifiers outside the
namespace can access the members
by using the fully qualified name for
each identifier.

C uses functions for input/output. For C++ uses objects for input output. For
example scanf and printf. example cin and cout.

C does not support reference variables. C++ supports reference variables.

C has no support for virtual and friend C++ supports virtual and friend
functions. functions.

C provides malloc() and calloc()functions for C++ provides new operator for


dynamic memory allocation, and free() for memory allocation
memory de-allocation. and delete operator for memory de-
allocation.

C does not provide direct support for error C++ provides support for exception
handling (also called exception handling) handling. Exceptions are used for
"hard" errors that make the code
incorrect.

5.Syntax of malloc ?
A:1.For integer-int* malloc(n*size of (int))
2.For character-char * malloc(n*sizeof (char)).

//6.Copy the arry1 to arry2 with different indexes ,what is the logic
you will use?(REPEATED)
7.Without using strlen library function ,how will you implement to find
length of string?
A: #include<stdio.h>
int main()
{
Char str[100],i;
printf(“Enter a String: \n”);
scanf(“%s”,str);
for(i=0; str[i]!= ‘\0’ ; ++i);
printf(”\n Length of input string:%d”,i);
return 0;
}
O/P:Enter a String
Embedded
Length of input String: 8

INVETECH info solution pvt.ltd


1.int a[10];
Printf(“ %p %p %p \n”, a,&a,&a[0]);
What is the program output?
//2.What is the difference between structures and unions ?Where do
we use unions? (REPEATED)
//3.Explain about function pointers and cal back functions?
4.What is void pointer, NULL pointer ,and their use?
A: A Null pointer is one which is not pointing to anything, i.e. it is assigned a null
value. If there is no address to assign to a pointer, it is considered a good practice
to set it to null. Every pointer type i.eint *, char * each have a null pointer value.
Syntax: <data type> *<variable name> = NULL;
Example: int *ptr = NULL;
                 char *ptr = '\0';
A void pointer is one which does not have any data type associated with it, i.e. it
can be assigned a value of any type. Also known as the general purpose pointer, it
is a C convention for a raw address. It is capable of storing addresses of any data
type.
Syntax: void *<data type>;
Example: void *ptr;
                 int a; char c;
                 ptr = &a; //ptr changes to integer pointer as address of integer is
assigned to it
                ptr = &c; //ptr changes to character pointer as address of character is
assigned to it

//5.Explain malloc ,calloc&realloc with examples? (REPEATED)


6.Bit manipulations using logic operaters, count the no,of 1’s in abyte?

7.Write a function to figure out ,if stack grows up or down ?


A: #include<stdio.h>
void fun(int *main_local_addr)
{
intfun_local;
if (main_local_addr<&fun_local)
printf("Stack grows upward\n");
else
printf("Stack grows downward\n");
}
int main()
{
// fun's local variable
intmain_local;
fun(&main_local);
return 0;
}
O/P: stack grows downward
8.Difference between stack and heap?
A:

9.Find little Endean and big endean with a example?


A:Little and big endian are two ways of storing multibyte data-types ( int, float,
etc). In little endian machines, last byte of binary representation of the multibyte
data-type is stored first. On the other hand, in big endian machines, first byte of
binary representation of the multibyte data-type is stored first.

Suppose integer is stored as 4 bytes (For those who are using DOS based
compilers such as C++ 3.0 , integer is 2 bytes) then a variable x with value
0x01234567 will be stored as following.
Eg:
#include <stdio.h>
int main()
{
unsigned inti = 1;
char *c = (char*)&i;
if (*c) 
printf("Little endian");
else
printf("Big endian");
getchar();
return 0;

O/P: Little endian

10.Explain about DMA?


A:The process of allocating memory during program execution is called dynamic
memory allocation.C language offers 4 dynamic memory allocation functions.
They are,1.malloc() 2.calloc() 3.realloc() 4.free()

Function Syntax
malloc () malloc (number *sizeof(int));

calloc () calloc (number, sizeof(int));

realloc () realloc (pointer_name, number * sizeof(int));

free () free (pointer_name);

11.inti= 9;
i= !i> 15;
printf(“i= %d”, i);
what is the output?
12. char j[ ] ={ ‘a’ ,’ b’,’c’,’\n’,’ c’,’\0’};
Char *p,*str, *str1;
P= &j[3];
Str = p;
Str1= j;
Printf(“%d”, ++*p+ ++*str1-32);
What is the output?
13. int a[2][2][2] ={{10,2,3,4},{5,6,7,8}};
Int *p, *q ;
P=&a[2][2][2];
*q =***a;
Printf(“ %d ------ %d”, *p,*q);
What s out put?
14. char *p= “hi friends”, *p1;
P1=p;
While(*p!=’\0’)
++*p++;
Printf(“%s %s ”,p,p1);
What is the output?

MBIT
1.Find middle node in a linked list ?
A:In order to find middle element of linked list in one pass, you need to maintain
two pointers, one increment at each node while other increments after two
nodes at a time. By having this arrangement, when first pointer reaches end,
second pointer will point to middle element of linked list.
https://www.geeksforgeeks.org/write-a-c-function-to-print-the-middle-of-the-
linked-list/

2.What is merge sort?


A:Merge Sort is a Divide and Conquer algorithm. It divides input array in two halves, calls
itself for the two halves and then merges the two sorted halves. The merge() function is
used for merging two halves. The merge(arr, l, m, r) is key process that assumes that
arr[l..m] andarr[m+1..r] are sorted and merges the two sorted sub-arrays into one.

https://www.geeksforgeeks.org/merge-sort/
3.Structure padding
struct a
{ int a;
Char b;
Float c;
Short d;
}
Struct a
{
Int *a;
Char *b;
Float *c;
Short *d;
}
Fill the above structure members and print the values in the structure
members?
4.How to avoid structure padding ?
A: https://www.allinterview.com/showanswers/62991/how-to-avoid-
structure-padding-in-c.html

5.Modulo operation without “%” .


A: #include
intmain()
{
intno,divisor,remainder;
printf("Enter the number : ");
scanf("%d",&no);

printf("Enter the divisor : ");


scanf("%d",&divisor);
while(no >= divisor)
{
no = no - divisor;
}
remainder = no;

printf("The remainder is %d ",remainder);

return0;
}

6.How to exit from while loop without using return ,break, continue ?
A:
7.How to extract 5 to 10 bits in a integer ?
A:

PATHPARTNER
1.Write recursive function to write (x%y) using multiple substance.
2.Using 2 arrays write a function to find common element in both A
and B arrays.
3.find the output of the following program
main()
{
intx,y;
x=5=N;
fib( );
printf(“%d”, x);
}
int fib(int n)
{
intNum,
N;
return ;
printf(“%d”,N);
x - -;
fib( );
return ;
}

4.Functions for binary input to convert all numbers to 1 after 1’s bit.
0000 0000 0000 0001 1100
0000 0000 0000 0001 1111
5.Write a program to use space and time complexity for count
multiple integers numbers with out using array.

TECH MAHINDRA
1.Write a program for swap two variables.
2.Write a program for fibnoic series?
3.Difference between structure and unions?
4.What are the storage class or variables and explain?
5.Difference between macro and typedef with examples?
What is function pointer?
7.Is it possible static is variable in another file?why?
8.What is inline function ?(c++).
9.Can we use static for functions or not?
VALEO
1.Explain about volatile keyword?(with example)
2.Difference between static function and non static function?
3.What is bit field with example?
4.What is the use of register keyword?
5.Which is the better loop for infinity loop in c?
6.How raw values are converted into human understandable
values(explain logic)?
7.Write a C program for triangle or pyramid?
8.main( )
{
printf(“%p”,main);
}
What is the output of the program?
9.main( )
{
clrscr( );
}
clrscr( );
what is output?
10.main( )
{
char *p;
p=”hello”;
printf(“%c”,*P);
}
What is the output?

VIZZITECH SOLUTIONS
1.Difference between malloc&callloc?
2.storage classes in C?
3.Difference between long, short,double?
4.Explain Stack and Quees operations?
5.Use of pointers? ++*P increaments?
6.What is sorting?
7.Difference between bubble sorting and quick sorting ?
VOTARY TECH
1.Program for multiplication given by user. Multiplication number and
row no. to be multiplied given by the user
Ex: multiplication number 5, row =20
5*1=5 to 5*20=100;
Multiplication functionality done using functions.
2.Enter the numbers ex:5, the range of no. is stored in an array. Write
a program using functions to print the reverse of given array and main
function program is used only to print reverse numbers.
3.Program to print the prime numbers ,given by the user (10 to 1000),
(50 to 2000)and program using functions.
4.write the decimal output for following.(no need of program)just write
steps.
I) v1=45, v2=036
v1&v2, v1|v2, v1^v2
ii) v1=49, v2= 12;
v1&v2, v1|v2, ~v1, v1>>3, v1<<2
iii) v1= 0xA5 ,v2=AB
v1&v2, v1|v2 , v1^v2, ~v1, ~v2, v1>>3, v1<<2

VOTARY TECH
1.what are the compilation stages in c? what are data types?
2.Difference between structures and unions?
3.What is palindrome ?write all four and five numbers palindram?
4. Linked list in python?
5. Recursion of a string print “hello world ”in python.
6.Diamand pattern with 1’s?
WINIT SOLUTIONS
1.Division of two numbers with division operator?
2.Linked list reverse and node deletion?
3.suduko validation/
4.In an array the absoult sum of two numbers real to zero.
5.Leadeship of numbers in an array/
6.Alternative words reverse?
7.Alternative prime numbers?
8.using single for loop find 3 largest elements in an array/
9.using single for loop compare two arrays having common elements?
10.Rotation of array checking ?
XPETIZE
1.Why we use typecasting?
2.Difference between typecasting and typedef?
3.C compilation steps?
NCR
1.Can you write a program to display prime numbers for range n given
by the user?
2.Write a program for fibnocci series?
3.Write a program for factorial of a given number using recursive
function?

/* automotive robotics on 22-01-2017 */


1.string reverse without using temp variable
2.dynamic memory allocation.
3.how to delete n node in linked list.
4.char x[50]={1,2,3,4,5,6,5,4,3,2,5,69,54,33,2,12,34,,54,9........};
int *iptr;
iptr=&x[10];
iptr-=2;
*iptr=25;

where 25 store?
5.inti=10;
printf("%d%d%d%d",++i,i/2,i,--i/2);

/* Globaledge telephonic interview on 15-02 */


1.what is static keyword.
2.copy from user and copy to user.
3.can we use memcopyinsteadof copy from user and copy to user.
4.Have you use function pointers.how do they works.

/* HCL interview on 25-02 first round written test second round face to
face */

1.clear a 9th bit in an integer.


2.enum day{monday,tuesday,wednesday};
3.reverse string.
4.strstr,strcat,strchar.
5.size of int a b,c;c=65545+65545.
6.size of long,double,longdouble,int,float.
7.dynamic creation of 3 dimensional array.
8.in a 64 bit byte swapping.
9.binary tree search.
10.a=o24 printf("%d",a);

/*--------------*/

1.Pointers, memset, code optimization technique.


2.Structures ,Unions difference.
3.What is #define function.

/* MBbit wireless on 29-01 face to face and skype */

1. n*5;
1=n
2=n-1;
3=n-3;

2.in a integer multiply 3rd byte and 2 byte


3.algartham for binary search
4.n&(n-1)
5.what is typedef and #define
6.what is macro and inline
7.volatile keyword and where it is stored
8.what is static keyword and where it is stored?
/*static is a storage variable(global variable)
initiated global variables are stored in data segment
unintiated global variables are stored in BSS segment*/.

9.using string pointer swap HELLO WROLD


10.int a=3,b=5,c;

c=a+++7;
11.how to return multiple values from a function.
using call by reference.

/* qualcommtelephoic interview oon 23-02* /

1.what are bit wise operators?


2.how to set a bit?
3.how to clear a bit?
4.in a int variable assign a vlaue and then swap the bit positions i.e in
32 bits swap 0,1 and 2,3......30,31.
5. unsignedint x=9;
power(x);

int power(unsigned int x)


{
unsignedinti;
if(x==0)
return 1;
for(i=x-1;i<=0;++i)
{
result *=2;
}
return result;
}

6.what is volatile keyword and how it is works?

/* unik system on 07-02 */

1.what is macro and inline.explain with an example.


2.what is volatile?
3.write a macro for swapping two variables.
4.in a 16 bit compiler,int x=4.set 7th bit.
5.reverse linked list.

/*winit software*/

1st round
1.Write a program for digital watch.
2.Write a program for decimal number to 1.octal 2.hexadecimal 3.
Binary .

3.Write a program for this pattern.

n=4; n=5;

2 1
1 2 3 12
1 2 3 4 1 2 3
1 2 3 1 2 3 4
1 1 2 3 4 5
1 2 3 4
1 2 3
1 2
1
4. Write aprogram for finding no.fo Zeros & ones and display them .
5. Write aprogram for the given numbers in order like asssending and
desending order.
6.Writea program for to create a tree.

/*votary tech*/
//1.malloc,calloc explain it.
2.Write a program for the ATM cash withdraw what logic you used.
A:
3.Reversing a string.
4.Tell me about some sorting technics?

You might also like