CoolInterview.com - World's Largest Collection of Interview Questions & Answers, FAQs, queries, sample papers, exam papers, dumps, what, why, how, where, when questions
Our Services
Get 9,000 Interview Questions & Answers in an eBook.




Get it now !!
Send your Resume to 6000 Companies
Arrays in C Interview Questions & Answers - Learning Mode
COOLINTERVIEW.COM C INTERVIEW QUESTIONS ARRAYS IN C INTERVIEW QUESTIONS QUESTIONS & ANSWERS - LEARNING MODE

Arrays in C Interview Questions & Answers - Learning Mode

An array is a collection of data items, all of the same type, accessed using a common name. A one-dimensional array is like a list; A two dimensional array is like a table; The C language places no limits on the number of dimensions in an array, though specific implementations may. Arrays a kind of data structure that can store a fixed-size sequential collection of elements of the same type. An array is used to store a collection of data, but it is often more useful to think of an array as a collection of variables of the same type.

Try Arrays in C Interview Questions & Answers - Exam Mode

1

Sort By : Latest First | Oldest First | By Rating

Arrays in C Interview Questions & Answers - Learning Mode
Try Arrays in C Interview Questions & Answers - Exam Mode
Question: When does the compiler not implicitly generate the address of the first element of an array?

Answer: Whenever an array name appears in an expression such as

?array as an operand of the sizeof operator

?array as an operand of & operator

?array as a string literal initializer for a character array

Then the compiler does not implicitly generate the address of the address of the first element of an array. Source: CoolInterview.com
Question: Can the sizeof operator be used to tell the size of an array passed to a function?




Answer: No. There?s no way to tell, at runtime, how many elements are in an array parameter just by looking at the
array parameter itself. Remember, passing an array to a function is exactly the same as passing a pointer to
the first element. Source: CoolInterview.com
Question: Write a program to insert an element in a linear array array?

Answer: /*Inserting an element into and deleting an element from an array*/
#include<stdio.h>
#include<conio.h>
void display(int*,int);
void insert(int*,int*,int,int);
void del(int*,int*,int);
int main()
{
int a[10],noe;
int i,pos,nel;
printf("
Enter noe");
scanf("%d",&noe);
for(i=0;i<noe;i++)
scanf("%d",&a[i]);
display(a,noe);
printf("
Enter the position and element to be inserted");
scanf("%d %d",&pos,&nel);
insert(a,&noe,pos,nel) Source: CoolInterview.com
Question: Array is an lvalue or not?

Answer: An lvalue was defined as an expression to which a value can be assigned. Is an array an expression
to which we can assign a value? The answer to this question is no, because an array is composed of several separate array elements that cannot be treated as a whole for assignment purposes.

The following statement is therefore illegal:

int x[5], y[5];
x = y;

Additionally, you might want to copy the whole array all at once. You can do so using a library function such as th Source: CoolInterview.com
Question: Write a program to delete an element from an array?

Answer: Programming's = loads of fun!!!!!!!
#include <stdio.h>
#include <conio.h>
#define size 10
void main()
{ int a[size],del,j,i;
clrscr();
for(i=0;i<size;i++)
{j=i+1;
printf("
Enter the %d element of array",j);
scanf("%d",&a[i]);}
printf("
Enter the element to be deleted");
scanf("%d",&del);
del--;
for(i=del;i<size-1;i++)
a[i]=a[i+1];
a[size-1]=0;
printf("
Element has been deleted");
CoolInterview.com
Question: How would you use qsort() function to sort the name stored in an array of pointers to string?

Answer:
Question: How to remove duplicate elements from an array



Answer: #include<conio.h>
#include<stdio.h>
#include<string.h>
void main()
{
//abcd are occurs two times in an array f[30]
char f[30]={"abcdabcd"},name[30];
int i,j,m,n;
clrscr();
m=strlen(f);
n=m;
for(i=0;i<n;i++)
for(j=i+1;j<m;j++)
if(f[i]==f[j])
{
f[j]='$';
}
j=0;
printf("name=%s",f);
for(i=0;i<m;i++)
{
if(f[i]!='$')
{
name[j]=f[i];
j++;
Source: CoolInterview.com
Question: Is it better to use a pointer to navigate an array of values,or is it better to use a subscripted array name?




Answer: It?s easier for a C compiler to generate good code for pointers than for subscripts.
Source: CoolInterview.com
Question: What is the difference between null array and an empty array?

Answer: int* arr[] when you declare it as globel it contais only null that means null array.
the array which cantain 0 elements is called empty array.
by my assemtion Source: CoolInterview.com
Question: Can the sizeof operator be used to tell the size of an array passed to a function?

Answer: No. There?s no way to tell, at runtime, how many elements are in an array parameter just by looking at the array parameter itself. Remember, passing an array to a function is exactly the same as passing a pointer to the first element. Source: CoolInterview.com
Question: Code for swapping of two numbers without using temporary variable using C.

Answer: int a=10,b=5;

a=a+b; // a=15
b=a-b; // b=10
a=a-b; // a=5
Source: CoolInterview.com
Question: Is it better to use a pointer to navigate an array of values,or is it better to use a subscripted array name?

Answer: It?s easier for a C compiler to generate good code for pointers than for subscripts. Source: CoolInterview.com
Question: How can you sort the elements of the array in descending order?

Answer: By calling Sort() and then Reverse() methods. Source: CoolInterview.com
Question: Can we add the name as "Mixed Arrays" instead of the name given as "Structures" in c?why the name structure is given?

Answer: Array is collection of variables of same data type. structure is collection of variables of same or dissimilar data types but logically related. structure is like a user defined data type arrays are derived data type. The name "Mixed Array" does'nt make sense. Source: CoolInterview.com
Question: Write a program for n lines
1 2 3 4 5
16 17 18 19 6
15 24 25 30 7
14 23 22 21 8
13 12 11 10 9


Answer: #include<stdio.h>
#include<conio.h>
int fillborder(int [15][15],int,int[],int,int);
int rowfillforward(int [15][15],int[],int,int);
int colfilldown(int [15][15],int[],int,int);
int rowfillback(int [15][15],int[],int);
int colfillup(int [15][15],int[],int);
void initmatrix(int[15][15],int);
void displaymatrix(int[15][15],int);
int main()
{

int size,bordersize,storevalue=1,matrix[15][15],pos[2];

printf("Enter the size of Matrix :");
scan Source: CoolInterview.com
Question: Can the size of an array be declared at runtime?

Answer: No. In an array declaration, the size must be known at compile time. You can?t specify a size that?s known only at runtime. For example, if i is a variable, you can?t write code like this:

char array[i]; /* not valid C */

Some languages provide this latitude. C doesn?t. If it did, the stack would be more complicated, function calls would be more expensive, and programs would run a lot slower. If you know that you have an array but you won?t know until runtime how big it will be, de Source: CoolInterview.com
Question: Does mentioning the array name gives the base address in all the integers?

Answer:
Question: Write a program using an array that computes the sum and the average of nth input values from the keyboard and prints the calculated sum and average.

Answer: #include<stdio.h>
#include<conio.h>
#define MAX 25

void main()
{
int a[MAX],i,sum=0,n;
float avg;

clrscr();

printf(" Enter size of array:");
scanf("%d",&n);
printf(" Enter %d elements of array",n);

for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}

for(i=0;i<n;i++)
{
sum=sum+a[i];
}
avg=(float)sum/n;
printf(" Sum=%d",sum);
printf(" Average=%f",avg);

getch();

} Source: CoolInterview.com

1



India News Network
Latest 20 Questions
Payment of time- barred debt is: (a) Valid (b) Void (c) Illegal (d) Voidable
Consideration is defined in the Indian Contract Act,1872 in: (a) Section 2(f) (b) Section 2(e) (c) Section 2(g) (d) Section 2(d)
Which of the following is not an exception to the rule, "No consideration, No contract": (a) Natural love and affection (b) Compensation for involuntary services (c) Completed gift (d) Agency
Consideration must move at the desire of: (a) The promisor (b) The promisee (c) The promisor or any other party (d) Both the promisor and the promisee
An offer which is open for acceptance over a period of time is: (a) Cross Offer (b) Counter Offer (c) Standing Offer (d) Implied Offer
Specific offer can be communicated to__________ (a) All the parties of contract (b) General public in universe (c) Specific person (d) None of the above
_________ amounts to rejection of the original offer. (a) Cross offer (b) Special offer (c) Standing offer (d) Counter offer
A advertises to sell his old car by advertising in a newspaper. This offer is caleed: (a) General Offer (b) Special Offer (c) Continuing Offer (d) None of the above
In case a counter offer is made, the original offer stands: (a) Rejected (b) Accepted automatically (c) Accepted subject to certain modifications and variations (d) None of the above
In case of unenforceable contract having some technical defect, parties (a) Can sue upon it (b) Cannot sue upon it (c) Should consider it to be illegal (d) None of the above
If entire specified goods is perished before entering into contract of sale, the contract is (a) Valid (b) Void (c) Voidable (d) Cancelled
______________ contracts are also caled contracts with executed consideration. (a) Unilateral (b) Completed (c) Bilateral (d) Executory
A offers B to supply books @ Rs 100 each but B accepts the same with condition of 10% discount. This is a case of (a) Counter Offer (b) Cross Offer (c) Specific Offer (d) General Offer
_____________ is a game of chance. (a) Conditional Contract (b) Contingent Contract (c) Wagering Contract (d) Quasi Contract
There is no binding contract in case of _______ as one's offer cannot be constructed as acceptance (a) Cross Offer (b) Standing Offer (c) Counter Offer (d) Special Offer
An offer is made with an intention to have negotiation from other party. This type of offer is: (a) Invitation to offer (b) Valid offer (c) Voidable (d) None of the above
When an offer is made to the world at large, it is ____________ offer. (a) Counter (b) Special (c) General (d) None of the above
Implied contract even if not in writing or express words is perfectly _______________ if all the conditions are satisfied:- (a) Void (b) Voidable (c) Valid (d) Illegal
A specific offer can be accepted by ___________. (a) Any person (b) Any friend to offeror (c) The person to whom it is made (d) Any friend of offeree
An agreement toput a fire on a person's car is a ______: (a) Legal (b) Voidable (c) Valid (d) Illegal
Cache = 0.0625 Seconds