| Back to Questions Page |
| |
| Question |
main is a predefined or user define function
if user defined why?
if predefined whay? |
Rank |
Answer Posted By |
|
Question Submitted By :: Pradeep.techbuzz |
| This Interview Question Asked @ TCS |
|
I also faced this Question!! |
© ALL Interview .com |
| Answer | actually main function is a user defined function for the C
compiler developer.... but it is a built in or predefined
function according to the users using that compiler.... why
it is called as a predefined function because , the
prototype has already been defined in the compiler itself
we the users can't change the meaning of that unless or
until we write our own compiler , we can change the meaning
of main()......
for the main() , we don't know what is the prototype or
where the function has been called and wht excatly the
return value of it... it is built in and abstracted from the
user which is called abstraction in c++.........
thank u  |
| Vignesh1988i |
| |
| |
| Answer | the main() is a predefined function because we can't change
the name of the function or characterstics of the function.
If the function is user defined means we can change the
name of the function as we wish.
So,the main() is a predefined function.  |
| S.s.venkatesh [Techbuzz] |
| |
| |
| Question |
how to print a statement in c without use of console
statement ,with the help of if statement it should print
|
Rank |
Answer Posted By |
|
Question Submitted By :: Hemavathy |
| This Interview Question Asked @ Satyam |
|
I also faced this Question!! |
© ALL Interview .com |
| Answer | #include <stdio.h>
void main()
{
if(printf("Hello World"))
}  |
| Girish |
| |
| |
|
|
| |
| Answer | #include<stdio.h>
void main()
{
if(printf("deepanshu kakkar"));
}  |
| Deepanshu Kakkar |
| |
| |
| Question |
array contains zeros and ones as elements.we need to bring
zeros one side and one other side in single parse.
ex:a[]={0,0,1,0,1,1,0,0}
o/p={0,0,0,0,0,1,1,1} |
Rank |
Answer Posted By |
|
Question Submitted By :: Chan |
| This Interview Question Asked @ Motorola , Google |
|
I also faced this Question!! |
© ALL Interview .com |
| Answer | #include<stdio.h>
#include<conio.h>
void main()
{
int *pointer,*pointer2,n;
printf("enter the no. of elements:");
scanf("%d",&n);
pointer=(int*)malloc(n*sizeof(n));
pointer2=(int*)malloc(n*sizeof(n));
for(int k=0,i=0,j=n-1;k<n;k++)
{
scanf("%d",(pointer+k));
if(*(pointer+k))
{
*(pointer2+(j))=*(pointer+k);
j--;
}
else
{
*(pointer2+i)=*(pointer+k);
i++;
}
}
for(i=0;i<n;i++)
printf("%d ",*(pointer2+i));
getch();
}
thaank u  |
| Vignesh1988i |
| |
| |
| Answer | I Hope this will also work for this question.
I just took it for length of 8 but we can extend it to any
level.
void swap(int* p, int x, int y)
{
int tmp;
tmp = *(p+x);
*(p+x) = *(p+y);
*(p+y) = tmp;
}
int main()
{
int* ptr = (int*)malloc(sizeof(8));
int c, i, j;
for(c=0; c<8 ; c++) scanf("%d", ptr+c);
for(i=0; i<8; i++)
{
for(j=0; j<8; j++)
{
if( *(ptr+j) > *(ptr+j+1) ) swap(ptr, j, j+1);
}
}
for(c=0;c<8;c++) printf("%d", *(ptr+c));
return 0;
}
 |
| Satinder Singh |
| |
| |
| Answer | good morning sir,
in ur above program , u said u took then length as 8 and
then allocated ur memory using DMA... but ur way of
allocation find to be wrong sir.... as you allocated
int *ptr=(int*)malloc(sizeof(8));
the above statement will allocate only 2 bytes for u....
since you have given 8 inside sizeof operator.. this will
tell the compiler allocate 2 bytes of memory .. ur
instruction must be :
int *ptr=(int*)malloc(8*sizeof(int));
so, then it will allocate 8*2 bytes of memory sir.....
so only in my program i have given n*sizeof(int) , where
'n' can be any value that user gives........
thank u  |
| Vignesh1988i |
| |
| |
| Answer | This program will work perfectly. I hope this is the exact
answer to the question.
#include<stdio.h>
void swap(int *a, int *b)
{
int temp;
temp = *b;
*b=*a;
*a=temp;
}
int main()
{
int a[]={0,0,1,0,1,1,0,0};
int i,j;
for(i=0;i<8;i++)
{
if(a[i])
{
j=i+1;
while(j<8)
{
j++;
if(!a[j])
{
swap(&a[i],&a[j]);
break;
}
}
}
}
for(i=0;i<8;i++)
printf("%d ",a[i]);
return;
}  |
| Rizwan |
| |
| |
| Answer | #include <stdio.h>
int main() {
int a[8] = {1,0,1,0,1,0,0,1};
int i = 0,j=0;
int sorted = 1;
for(i=0;i<8;i++) {
if (a[i]) continue;
/* Find the nearest one and swap */
for(j=i+1;j<8;j++) {
if (a[j]) {
a[j] = a[i] + a[j];
a[i] = a[j] - a[i];
a[j] = a[j] - a[i];
sorted = 0;
break;
}
}
if (sorted) { break;}
}
printf("\nSorted Array is { ");
for (i=0;i<8;i++) { printf("%d,",a[i]); }
printf("}\n");
}  |
| Rajasekaran |
| |
| |
| Answer | #include<stdio.h>
#include<conio.h>
void main()
{
int a[]={0,0,1,0,1,1,0,0};
int t,j=0,k=0;
while(a[j]!='\0')
{
if(a[j]==1)
j++;
if(a[k]==0)
k++;
t=i;
a[i]=a[j];
a[j]=a[t];
printf("%d",a[j]);
}
}  |
| Ashok Kannan |
| |
| |
| Answer | #include<stdio.h>
#include<conio.h>
void main()
{
int a[]={0,0,1,0,1,1,0,0};
int *arrayTemp = a;
int i, j_0 = 0, j_8 = 8;
for(int data = 0; *a != '\0'; *a++)
{
data = *a;
if(data == 1 )
{
a[j_0++] = data;
}
else
{
a[j_8--] = data;
} // if-else block
}//for loop
}//main function
for(i=0; i< 8; i ++)
{
printf("array value is %d", a[i]);
}  |
| Manoj |
| |
| |
| Question |
How to add two numbers with using function?
|
Rank |
Answer Posted By |
|
Question Submitted By :: Tahir.faridi |
|
I also faced this Question!! |
© ALL Interview .com |
| Answer | this has been demonstrated by a simple program.......
in C we ourselves can write a function for addition and
include wherver we want to add numbers.....
1) first write the function definition for the function u
are gonna write for addition....in a new file
int addition_arthmetic(int a, int b)
{
return(a+b);
}
2) dont run or compile this , directly save this file in .c
extension.. let us say "add.c".
3) then open a new file and write the program for addition
by getting the 2 i/p from the user...
#inclue<stdio.h>
#include<conio.h>
#include "add.c" // we are including tthe file add.c"
void main()
{
int a,b,c;
printf("enter the values for a&b");
scanf("%d%d",&a,&b);
c=addition_arthmetic(a,b);// we call the function defined in
add.c
printf("\n\n the added value of a&b is :%d",c);
getch();
}
thank u  |
| Vignesh1988i |
| |
| |
| Answer | #include<stdio.h>
#include<conio.h>
void main()
{
int a,b,i;
int sum=0;
clrscr();
printf("Enter Two Nos");
scanf("%d%d",&a,&b);
for(i=0;i<a;i++)
sum=sum+1;
for(i=0;i<b;i++)
sum=sum+1;
printf("Sum:%d",sum);
getch();
}  |
| Sathish Kumar .k |
| |
| |
| Answer | #include<stdio.h>
#include<conio.h>
void main()
{
int add(int,int);
int a,b;
clrscr();
printf("Enter two numbers: ");
scanf("%d %d",&a,&b);
printf("The Sum is: %d",add(a,b));
getch();
}
int add(int x,int y)
{
return(x+y);
}  |
| Anandi |
| |
| |
| Question |
what is the difference between entry control and exit
control statement? |
Rank |
Answer Posted By |
|
Question Submitted By :: Devilboy |
|
I also faced this Question!! |
© ALL Interview .com |
| Answer | Entry Comtrolled will check the Condition at First and
doesn't execute if it is False.
Exit Comtrolled will check the Condition at Last and at
least once the statement will execute though it is False .  |
| Ksk |
| |
| |
| Answer | Entry control is otherwise called as WHILE loop,because the
while loop checks the condition at first,and then only
execute the following instructions.
Exit control is also called as DO WHILE loop,because the do
while loop checks the condition at last  |
| S.s.venkatesh |
| |
| |
| Question |
Why is conio.h not required when we save a file as .c and
use clrscr() or getch() ? |
Rank |
Answer Posted By |
|
Question Submitted By :: Elizabeth |
|
I also faced this Question!! |
© ALL Interview .com |
| Answer | not only conio.h , also stdio.h we dont need while saving a
C program with the extension '.c'... but in recent turbo C
or borland C compilers only it's allowing , it may be to
reduce the time of typing these files to include rather
getting automatically included.....
and even we can type main() instead of void main() , it is
accepting with the warning.............
thank u  |
| Vignesh1988i |
| |
| |
| Answer | not only conio.h , also stdio.h we dont need while saving a
C program with the extension '.c'... but in recent turbo C
or borland C compilers only it's allowing , it may be to
reduce the time of typing these files to include rather
getting automatically included.....  |
| Kuldeep Yadav |
| |
| |
| Question |
if array a conatins 'n' elements and array b conatins 'n-1'
elements.array b has all element which are present in array
a but one element is missing in array b. find that
element. |
Rank |
Answer Posted By |
|
Question Submitted By :: Guest |
| This Interview Question Asked @ Zycus-Infotech , Ram |
|
I also faced this Question!! |
© ALL Interview .com |
| Answer | add the sum of elements in array a and then that of array
b.. subtract the sums of the two arrays a and b. ul get the
missing element  |
| Nikita |
| |
| |
| Answer | define one variable say t_max and save a[0] in that,loop
through it, if a[1] is grater than a[0] save a[1] in t_max
otherwisw a[0] remain as it is....check it same way for all
elemnts in array...finally t_max will hold max elemnt from
array.  |
| Rahul |
| |
| |
| Answer | firt do sum of n elements in first array a i.e., n(n+1)/2
next the sum of n-1 elements in second array b i.e., n(n-1)/2...
from diff of these 2 sums we will get the missing element in b  |
| Sumanth |
| |
| |
| Answer | a[0]  |
| Guest |
| |
| |
| Answer | It is not true that there is a[0] missing.
Because as per my knowledge array is starting from a[0] and
running up to a[n] continuously.
But if my ans is wrong then sorry and please send me right ans.  |
| Bhavik |
| |
| |
| Answer | The answers are only applicable to array of numbers.. what
if the array is of strings..?  |
| Rasika |
| |
| |
| Answer | a[n] is missing in b bcoz a contains n,(n-1),(n-2)....
and b contains n-1,n-2,.....so hear n is missing  |
| Navs |
| |
| |
| Answer | the question says that we have to find the element which is
not there in array b but there in array a. So we can just
compare each element in a with all the elements in b and if
we don't find a match then that is the desired element.  |
| Brijesh |
| |
| |
| Answer | Take a temp variable of datatype of the array element.
Place a[0] in temp.
now for each element in array a compare with all elements
of array b. if any element is not found in array b, that is
the missing element.
what i guess though is that the interviewer may be trying
to look for a short-cut method to achieve the above. So, i
googled it and found a very nice answer:
http://stackoverflow.com/questions/1235033/java-comparing-
two-string-arrays-and-removing-elements-that-exist-in-both-
arrays  |
| Ajay C. |
| |
| |
| Question |
find largest element in array w/o using sorting techniques. |
Rank |
Answer Posted By |
|
Question Submitted By :: Guest |
| This Interview Question Asked @ Zycus-Infotech |
|
I also faced this Question!! |
© ALL Interview .com |
| Answer | #include<stdio.h>
int main()
{
int a[10]={13,12,34,56,73,21,234,5,76,2};
int tmp,i;
tmp=a[0];
for(i=0;i<=9;i++)
{
if(a[i]>tmp)
{
tmp=a[i];
}
}
printf("\n largest number is %d\n",tmp);
return 0;
}  |
| Pramod |
| |
| |
| Answer | #include<stdio.h>
void main()
{
int a,b[4]={3,2,7,4,9};
a[0]=b[0];
for(i=1;i<5;i++)
{
if(a<b[i])
{
a=b[i];
}
}
printf("the largest num is %d",a);
}  |
| Manjunath |
| |
| |
| Question |
find second largest element in array w/o using sorting
techniques? use onle one for loop. |
Rank |
Answer Posted By |
|
Question Submitted By :: Guest |
| This Interview Question Asked @ Zycus-Infotech |
|
I also faced this Question!! |
© ALL Interview .com |
| Answer |
max = 2ndmax= array[0];
for (i=0;i,length;i++)
{
if (array[i]>max)
{
2ndmax=max;
max=array[i];
}
}
return 2nd max  |
| Guest |
| |
| |
| Answer | public static void main(String[] args) {
int array[]={13,12,34,56,73,21,232,234,235,240};
int max ,secndmax;
max = secndmax= array[0];
System.out.println("Initial value is "+ secndmax);
for (int i=1;i<array.length;i++){
if (array[i]>max ){
secndmax=max;
max=array[i];
}else if(array[i]>secndmax){
secndmax = array[i];
}
}
System.out.println("Max element is "+ max);
System.out.println("Second Max element is "+
secndmax);
}  |
| Ranjeet |
| |
| |
| Question |
WRITE A C PROGRAM TO FIND SECOND BIGGEST VALUE FROM THE
GIVEN VALUES |
Rank |
Answer Posted By |
|
Question Submitted By :: Taj |
|
I also faced this Question!! |
© ALL Interview .com |
| Answer | #include<stdio.h>
#include<math.h>
void main()
{
int a[],n,b;
printf("Enter the number of digits you want to enter:");
scanf(%d",&n);
printf("Enter the different values you want:")
for(i=0;i<=n;i++)
{
scanf(%d",a[i]);
}
/* This will make the values to be arranged in descending
order*/
for(i=0;i<=n;i++)
{
if(a[i] >> a[i+1])
{
}
else
{
b = a[i];
a[i] = a[i+1];
a[i+1] = b;
}
}
/* As a[0] will be the max value the next to it a[1] will be
second highest*/
printf("The second largest value will be: %d",&a[1]);
}  |
| Naveen |
| |
| |
| Question |
Write a program for the following series?
1
121
12321
1234321
123454321
12345654321
1234567654321
123456787654321
12345678987654321
1234567890987654321
123456789010987654321
12345678901210987654321
1234567890123210987654321
.........1234321............
..........123454321............
..........12345654321............
7
8
9
0
1
Pls............? |
Rank |
Answer Posted By |
|
Question Submitted By :: Sai Shanker |
|
I also faced this Question!! |
© ALL Interview .com |
| Answer | #include<stdio.h>
#include<conio.h>
void main()
{
int i,j,k,a,n,s,p;
clrscr();
printf("enter the no. of lines :");
scanf("%d",&n);
a=n;
j=1;
for(i=1;i<=n;i++)
{
for(k=1;k<=(a-1);k++)
printf(" ");
a--;
for(k=1,p=1;k<=(i-1);)
{
if(!((k%10)^0))
p=0;
printf(%d",p);
k++; p++;
}
if(!((i%10)^0)
j=0;
printf("%d",j);
j++;
s=--p;
if(i>10)
{
for(;s>=0;s--)
printf("%d",s);
s=i-(p+1)-1;
}
for(;s>0;s--)
printf("%d",s);
printf("\n");
}
getch();
}
thank u , hope this works  |
| Vignesh1988i |
| |
| |
| Answer | hi this is no the pgrm
let u want to find nth number
value = "n";
while(n-1)
{
value = value+ "n-1";
value= "n-1" + value;
n= n-1;
}  |
| Kkx |
| |
| |
|
| |
|
Back to Questions Page |