ALLInterview.com :: Home Page KalAajKal.com
 Advertise your Business Here     
Browse  |   Placement Papers  |   Company  |   Code Snippets  |   Certifications  |   Visa Questions
Post Question  |   Post Answer  |   My Panel  |   Search  |   Articles  |   Topics  |   ERRORS new
   Refer this Site  Refer This Site to Your Friends  Site Map  Bookmark this Site  Set it as your HomePage   interview questions urls   External Links  Contact Us     Login  |  Sign Up                      
tip   SiteMap shows list of All Categories in this site.
Google
 
Categories  >>  Software  >>  Programming Languages  >>  C
 
 


 

 
 C interview questions  C Interview Questions
 C++ interview questions  C++ Interview Questions
 VC++ interview questions  VC++ Interview Questions
 Delphi interview questions  Delphi Interview Questions
 Programming Languages AllOther interview questions  Programming Languages AllOther Interview Questions
Question
pgm to reverse string  using arrays i.e god is love becomes 
love is god)
(assumption:only space is used for seperation of words)

no addtional memory used.i.e no temporary arrays can used.
 Question Submitted By :: Soumya Joy
I also faced this Question!!     Rank Answer Posted By  
 
  Re: pgm to reverse string using arrays i.e god is love becomes love is god) (assumption:only space is used for seperation of words) no addtional memory used.i.e no temporary arrays can used.
Answer
# 1
#include<stdio.h>
#include<conio.h>

int main()
{

    int i,j,length;
	char a[] = "god is love";

	length = strlen(a);
	
	printf("The Given String is\n%s\n",a);
	printf("The Resulted String is\n");

	for(i=length-1;i>=0;i--)
	{
		if(a[i] == ' ')
		{
			for(j=i+1; a[j] != ' ' && a[j] != '\0';j++)
			{
				printf("%c",a[j]);
			}
			printf("%c",a[i]);
		}
	}
	i++;
	while(a[i] !=' ')
	{
		printf("%c",a[i]);
		i++;
	}
	printf("\n");

}
 
Is This Answer Correct ?    1 Yes 0 No
Santhi Perumal
 
  Re: pgm to reverse string using arrays i.e god is love becomes love is god) (assumption:only space is used for seperation of words) no addtional memory used.i.e no temporary arrays can used.
Answer
# 2
#include <stdio.h>

void reverse_string ( char* cp_string, int start, int end )
{
	if ( cp_string && ( start < end ) ) {
		*( cp_string + start ) ^= *( cp_string + 
end  ) 
			^=  *( cp_string + start ) ^= *( 
cp_string + end );
		reverse_string ( cp_string, ++start, --
end ); 
	}
}


int main ( int argc, char* argv [] )
{
	char ca_array [12]={"Hello World"};
	char* cp_ptr = NULL;
	char* cp_ptr_temp = NULL;
	
	printf ( "\n Before Reverse :%s", ca_array );

	reverse_string ( ca_array, 0, strlen ( ca_array ) -
1 );

	cp_ptr_temp = cp_ptr = ca_array;
	while ( NULL != ( cp_ptr_temp = (char*) strchr ( 
cp_ptr_temp, ' ' ) ) ) {
		reverse_string ( cp_ptr, 0, ( cp_ptr_temp - 
cp_ptr ) - 1 );
		cp_ptr = ++cp_ptr_temp;
	}
	// change the final word
	reverse_string ( cp_ptr, 0, ( ( strlen ( 
ca_array ) - 1 ) - ( cp_ptr - ca_array ) ) );

	printf ( "\n After Reverse by Words :%s", 
ca_array );
	return ( 0 );
}
 
Is This Answer Correct ?    0 Yes 0 No
Abdur Rab
 
 
 

 
 
 
Other C Interview Questions
 
  Question Asked @ Answers
 
write a program to swap Two numbers without using temp variable. HP16
Blade logic interview question. 1st round is a written tests with 15 multiple questions from c and c++. All are simple basic question. Like int main () { Int i=65; Return printf(“%c”, i); } 2nd and 3rd round is technical interview. The position for which I was interview was core UNIX and c. Yes it is for system programming. The company has product name blade server. For their server they are creating their own command for their purpose. Example cd command. We can implement it in a c program by using the chdir() function. So the question asks related to PID, fork, pipe, shared memory, signal. Write a program in c which will act as cp command. BladeLogic1
can we access one file to one directory?  1
char S; char S[6]= " HELLO"; printf("%s ",S[6]); output of the above program ? (0, ASCII 0, I,unpredictable) Mascot3
long int size a) 4 bytes b) 2 bytes c) compiler dependent d) 8 bytes HCL10
N O S I E R + A S T R A L ---------------- 7 2 5 6 1 3 Honeywell1
what is the difference between normal variables and pointer variables.............. Satyam4
what is compiler  5
what is the output of below pgm? void main() { int i=0; if(i) printf("pass"); else printf("fail"); }  2
How to calculate Total working time using Login and logout? Wipro2
consider the following C code main() { int i=3,x; while(i>0) { x=func(i); i--; } int func(int n) { static sum=0; sum=sum+n; return(sum); } the final value of x is TCS2
IS STRUCTURES CAN BE USED WITHIN AN ARRAY? Caritor7
write a program to print sum of each row of a 2D array.  2
what is the differance between pass by reference and pass by value. Infosys4
how to find out the reverse number of a digit if it is input through the keyboard?  1
WHAT IS MAXIMUM SIZE OF AN ARRAY IN C LANGUAGE? IBM4
What is the function of ceil(X) defined in math.h do? A)It returns the value rounded down to the next lower integer B)it returns the value rounded up to the next higher integer C)the Next Higher Value D)the next lower value Accenture3
What's the best way to declare and define global variables?  2
f() { int a=2; f1(a++); } f1(int c) { printf("%d", c); } c=? Geometric-Software2
Determine the code below, tell me exactly how many times is the operation sum++ performed ? for ( i = 0; i < 100; i++ ) for ( j = 100; j > 100 - i; j--) sum++; ITCO3
 
For more C Interview Questions Click Here 
 
 
 
 
 
   
Copyright Policy  |  Terms of Service  |  Help  |  Site Map 1  |  Articles  |  Site Map  |   Site Map  |  Contact Us
   
Copyright © 2007  ALLInterview.com.  All Rights Reserved.

ALLInterview.com   ::  Forum9.com   ::  KalAajKal.com