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  Contact Us     Login  |  Sign Up                      
info       Did you received any Funny E-Mails from your Friends and like to share with rest of our friends? Yeah!! you can post that stuff   HERE
Google
 
Categories >> Software >> Programming-Languages >> C
 
 


 

Back to Questions Page
 
Question
Will Macros support multiple arguments ?
Rank Answer Posted By  
 Question Submitted By :: Mittal
This Interview Question Asked @   Oracle
I also faced this Question!!   © ALL Interview .com
Answer
yes they will support multiple arguments
 
5
Phani Kumar S
 
 
Answer
Phani Kumar S. Please give me the detailed answer not only 
in Yes or No thanks


Plz correct me if i m wrong...
Regards..
Lokesh Kumar Chauhan 
lokesh_kumar_chauhan@yahoo.com
Noida
 
0
Lokesh Chauhan
 
 
Answer
no,
macros dont support multiple arguments..
 
0
Shruti
 
 
 
Answer
yes they will support multiple arguements

 they are the short forms for activate some internal 
functions
 
0
Phani Kumar Satpathi
 
 
Answer
variadic macros --- C99 standard

 #define MY_MACRO(...)
 
0
Ronald
 
 
Answer
Yes we Macros support Multiple Arguments.

If we want to swap two value using macro how i can do if 
you can do this then you know the ans.

or you can do one thing you chk greater no 
By macro like 
 Max(30,10);

defination like :- 
 
   Max(x,y) x>y?x:y

here i m passing 2 arguments.

ok bye bye.

thx.
 
0
Agent
 
 
Answer
defination like :- 
 
   Max(x,y) x>y?x:y
 
0
Phani Kumar S
 
 
Question
Why the use of alloca() is discouraged?
Rank Answer Posted By  
 Question Submitted By :: Mittal
This Interview Question Asked @   Oracle
I also faced this Question!!   © ALL Interview .com
Answer
Hi All,

If you use alloca inside a function when it retuns from 
function it will be resulting in memory leak.  Thats why 
its discouraged to use.

Thanks & Regards
Sathish Kumar
 
0
Sathish Kumar
 
 
Answer
Sorry, that is not strictly correct. According to the man page:

"The alloca() function allocates size bytes of space  in  the 
stack  frame  of  the  caller,  and returns a pointer to the 
allocated block. This temporary space is automatically freed 
when  the  caller  returns."

Now this is the real reason:
" If the allocated block is beyond the current stack limit, 
the  resulting  behavior  is  undefined."
 
0
Johnson
 
 
Question
what are brk, sbrk?
Rank Answer Posted By  
 Question Submitted By :: Mittal
This Interview Question Asked @   Oracle
I also faced this Question!!   © ALL Interview .com
Answer
These are the system calles used to allocate the memory. 
brk will call internally when u call malloc func.
 
0
Guest
 
 
Question
What is the Difference between Macro and ordinary 
definition?
Rank Answer Posted By  
 Question Submitted By :: Guest
This Interview Question Asked @   Motorola , Cognizant, Robert Bosch
I also faced this Question!!   © ALL Interview .com
Answer
1. Macro takes parameters where as ordinary definition does 
not.
2. Based on the parameter values to macro it can result in 
different value at run time. Ordinary defination value 
remains same at all place at run time.
3. Macro can be used for conditional operations where as 
definition can not.
4. Using macro one can achieve inline functionality in C 
ie. macro can be a function performing simple operations. 
This is not possible using definitions.
 
0
D G Patel
 
 
Answer
macro definitions can be used for conditional compilation
whereas ordinary cannot
 
0
Himanshu Goel
 
 
Question
What is the Difference between Class and Struct?
Rank Answer Posted By  
 Question Submitted By :: Guest
This Interview Question Asked @   Motorola
I also faced this Question!!   © ALL Interview .com
Answer
by default 
struct elements are public
while
class elements are private
 
0
Ashish Srivastava
 
 
Answer
Class elements are accessed using the provided methods.
 
0
Wfwre
 
 
Answer
no functions in structures
member functions are available in class
 
0
Revathy
 
 
Answer
The only difference between class and struct is that

in class all members are private by default whereas in 

struct the members are by default public.
 
0
Manju
 
 
Answer
1.the variables of struct r jus varialbles inly,whereas it 
it objects for class...

2. pointers can be used in structure only for same return 
types,but in classes it can be uses for diff classes
 
0
Vishnupriya
 
 
Answer
answer 3 is wrong.
answer 4 is absolutely corret.
 
0
Purna
 
 
Answer
the diff b/w structure and class is class by deafualt 
private, where as structure by default public.
 
0
Sureshreddy
 
 
Answer
STRUCTURE                         CLASS
1.structure by default is     1. class by default is private
public. 
2.structure does not          2.class provide data hiding.
provide data hiding. 
3.A structure would be the    3.class would be the collection
collection of related data.     of data & code which handels
                                      data.


CAN U TELL ME MORE DIFFERENCE BETWEEN LIKE THIS PLZ TELL ME
AS EARLY AS POSSIBLE I AM WAITING
 
2
Satvir Kaur
 
 
Answer
Structs allocates continues memory
where as class does not
structs and functions are the basic idea behind class
 
0
Santhosh.r
 
 
Question
How to reverse a string using a recursive function, without
swapping or using an extra memory?
Rank Answer Posted By  
 Question Submitted By :: Guest
This Interview Question Asked @   Motorola , Cisco, Sony
I also faced this Question!!   © ALL Interview .com
Answer
/* Following code does as intended */
#include <stdio.h>

#define REVERSE_STRING(X) Rstring(X, *(X), strlen(X)-1)

void Rstring( char *str, char c, int index )
{
	if( index != 0 )
		Rstring( str, *(str+(strlen(str))-index), 
index-1);	
	*(str+index) = c;		
}

int main( void )
{
	char str[] = "Dharmendra Patel";
	printf("Actual string is [%s]\n", str);
	REVERSE_STRING(str);
	printf("Reversed string is [%s]\n", str);
	return 0;
}
 
4
D G Patel
 
 
Answer
void reverse(char *,int b);
void main()
{
char a[26];
int len;
clrscr();
printf("enter string ");
gets(a);
len=strlen(a);
reverse(a,len);
getch();
}
void reverse(char * a,int len)
{
  if(len==0)
  printf("%c",a[len]);
  else
  {
  printf("%c",a[len]);
  reverse(a,len-1);
  }
}
 
1
Vinay Tiwari
 
 
Answer
void Rstring( char *str,int len)
{
	for(int i = 0; i < (len/2); i++)
	{
		str[i] ^= str[len-i-1];
		str[len-i-1] ^= str[i];
		str[i] ^= str[len-i-1];
	}
}

int main( void )
{
	char str[] = "my string";
	printf("Actual string is [%s]\n", str);
	Rstring(str,strlen(str));
	printf("Reversed string is [%s]\n", str);
	
}

I dont call this swaping, coz it's not, recursive creates 
new incarnations of the reverse func, EXTRA MEMORY BIG 
TIME!!!
 
3
Boomer
 
 
Answer
#include <iostream>
#include <conio>

void reverse(char a[], int s, int sc );

void reverse(char a[], int s, int sc ){

if ((sc-s)<(s-1))
{
a[sc-s]^=a[s-1];
a[s-1]^=a[sc-s];
a[sc-s]^=a[s-1];
reverse (a, s-1, sc) ;

}

}

void main (){


char a[]="ABCDEFG";

reverse(a, 7, 7);
cout<<a;
getch(); //i just use it to freeze the screen

}
 
1
Moinom
 
 
Answer
#include <iostream>


using namespace std;


char* reverse_str(char* s)
{
	char* reverse = new char[1];
	//char* reverse;


	int i;

	if(*s != '\0')
		reverse = reverse_str(s+1);

	i = strlen(s) - 1;

	if (i >= 0)
		reverse[i] = s[0];

	return reverse;
}


int main(void)
{
	char* str = "tsirhc oraivur odraude leafar";

	
	cout << "original:" << endl;
	cout << str << endl << endl;
	
	cout << "reversed:" << endl;
	cout << reverse_str(str) << endl;
	
	return 0;
}
 
1
Rafael Christ
 
 
Answer
/* 
  reverse string between start and end indexes of a string 
*/

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

int main()
{
  char sample[] = "My String!";
  reverse( str, 0, strlen( sample )-1 )
}
 
1
Pritam
 
 
Answer
#include <stdio.h>
#include <conio.h>
#include <string.h>
int main(void)
{

 char str1[] = "Mahesh";
 char str2[80], *p1, *p2;

 clrscr();

 p1 = str1 + strlen(str1) - 1;

 p2 = str2;

 while(p1 >= str1)
  *p2++ = *p1--;

 *p2 = '\0';

 printf("%s %s", str1, str2);

 getch();

 return 0;
}
 
0
Mahesh Auti
 
 
Answer
#include<stdio.h>
#include <string.h>

char * reverse (char *);		//function prototype
int length(char *);                     //function prptotype

void main()
{
    int i;
    char *str, *rev;
    clrscr();
    gets(str);
    strcpy(rev,reverse(str));

    printf("Original %s     Reverse %s", str, rev);
    free(str);
    free(rev);
    getch();
}

int length(char *s)
{
    int i;
    for (i=0; *(s+i)!='\0' ; ++i);
    return i;
}

char *reverse(char *s)
{
   char *t;
   int i, n;
   n=length(s);
   for (i=0; i<n; ++i)
   {
       *(t+i)=*(s+n-1-i);
   }
   *(t+i)='\0';
   printf("\nOUT: %s\n", t);
   return t;
}
 
0
Mahesh Auti
 
 
Answer
Reverse a string

void ReverseString (char *String)
{
char *Begin = String;
char *End = String + strlen(String) - 1;
char TempChar = '\0';

while (Begin < End) 
{
TempChar = *Begin;
*Begin = *End;
*End = TempChar;
Begin++;
End--;
}
}
 
0
Mahendra Aseri
 
 
Answer
Using recursive Function:

void rev_str(char *str)
{
	if(*str!=NULL)

  	rev_str(str+1);   

  printf("%c",str);
}
 
0
Mahendra Aseri
 
 
Answer
&#65279;#include <iostream>

using namespace std;

void rev_str(char* str, int pos=-1, char c='\0'){
    if(pos >= int(strlen(str)/2))
	return;
    if(c != '\0'){
	str[strlen(str) - pos - 1] = str[pos];
	str[pos] = c;
    }
    rev_str(str, ++pos, str[strlen(str) - pos - 2]);
}

int main(){
    char str[] = "reverse this string";
    cout << str << endl;
    rev_str(str);
    cout << str << endl;
    //:~
    return 0;
}
 
0
Smbrd
 
 
Answer
#include <iostream>
#include <string>
 using namespace std;
char * reverse (char *);		//function prototype
int length(char *);                     //function prptotype
 
int main()
{
    int i;
    char *str = new char[6], *rev = new char[6];
    cin >> str;
    strcpy(rev,reverse(str));

	cout <<"Original "<< str << " reverse " << rev << endl;
    free(str);
    free(rev);
	return 0;
}

int length(char *s)
{
    int i;
    for (i=0; *(s+i)!='\0' ; ++i);
    return i;
}

char *reverse(char *s)
{
   char *t;
   int i, n;
   n=length(s);
   t = new char[n];
   for (i=0; i<n; ++i)
   {
       *(t+i)=*(s+n-1-i);
   }
   *(t+i)='\0';
   
   return t;
}

/*based off of answer 8 i took this an intialized the
pointers so that it would run, and switched it over to the
C++ standard output commands. His algorithm was correct, he
just forgot to setup the memory*/
 
0
Stephen
 
 
Answer
#include <iostream>
#include <string>
 using namespace std;
char * reverse (char *);		//function prototype
int length(char *);                     //function prptotype
 
int main()
{
    int i;
    char *str = new char[6], *rev = new char[6];
    cin >> str;
    strcpy(rev,reverse(str));

	cout <<"Original "<< str << " reverse " << rev << endl;
    free(str);
    free(rev);
	return 0;
}

int length(char *s)
{
    int i;
    for (i=0; *(s+i)!='\0' ; ++i);
    return i;
}

char *reverse(char *s)
{
   char *t;
   int i, n;
   n=length(s);
   t = new char[n];   //opps have to add 1 here or there
wont be room for a null! 
   for (i=0; i<n; ++i)
   {
       *(t+i)=*(s+n-1-i);
   }
   *(t+i)='\0';
   
   return t;
}
//can only handle words 5 letters or less.
/*based off of answer 8 i took this an intialized the
pointers so that it would run, and switched it over to the
C++ standard output commands. His algorithm was correct, he
 
0
Stephen
 
 
Answer
#include <stdio.h>

void reverse(char *str)
{
	if (*str == '\0')
		return;

	reverse(str+1);

	printf("%c", *str);
}

int main()
{
	char str[50];

	printf("Enter the string: ");
	scanf("%s", str);

	printf("Reversed string: ");
	reverse(str);
	printf("\n");

	return 1;
}
 
0
Prakash
 
 
Answer
Another version that actually reverses the string...

#include <stdio.h>

char *reverse(char *sstr, char *str, char c)
{
	if (*str == '\0')
		return sstr;

	sstr = reverse(sstr, str+1, *(str+1));

	*sstr = c;

	return (sstr+1);
}

int main()
{
	char str[100];

	printf("Enter the string: ");
	scanf("%s", str);

	reverse(str, str, *(str + 0));
	printf("Reversed string: %s\n", str);

	return 1;
}
 
0
Prakash
 
 
Answer
main()
 {
  char str[10];
  cin>>str;
  int len=strlen(str);
  reverse(len);
  cout<<"Reversed string is: "<<str;
 }

void reverse(int len)
 {
  static int i=0;
  str[i]=str[len-1]; //put the char in last pos to first pos
  for(j=len-1;j>i;j--)
   str[j]=str[j-1]; //shift to right
  i++;
  
  if(i==len)
   return;
  
  reverse(len);
 }
 
0
Shivaraj
 
 
Answer
void reverse_string(char *string) {

    static int start_index = 0;
    static int end_index = strlen(string) - 1;

    if (start_index <= end_index) {
        char temp = string[end_index];
        string[end_index] = string[start_index];
        string[start_index] = temp;
        start_index++;
        end_index--;
        reverse_string(string);
    }
}
 
0
Siva Kumar
 
 
Answer
no ansawer
 
0
Fgy
 
 
Question
How to set a variable in the environment list?
Rank Answer Posted By  
 Question Submitted By :: Guest
I also faced this Question!!   © ALL Interview .com
Answer
environment variables can be get and set by getenv() and 
putenv() calls in C.
 
0
D G Patel
 
 
Question
What is sparse file?
Rank Answer Posted By  
 Question Submitted By :: Rasmi
I also faced this Question!!   © ALL Interview .com
Answer
A sparse file is a type of computer file that attempts to 
use file system space more efficiently when the file itself 
is mostly empty. This is achieved by not writing data to 
disk when it has been allocated but not actually filled 
with data. Instead, brief information about these empty 
regions is stored, which takes up much less disk space. 
These regions are only written to disk at their actual size 
when data is written to them; the file system transparently 
converts empty sections into blocks filled with zero bytes 
when read at runtime. Most modern file systems support 
sparse files, including most Unix variants and NTFS. Sparse 
files are commonly used for disk images, database 
snapshots, log files and in scientific applications.
 
0
Vivek
 
 
Question
What are the different pointer models in c?
Rank Answer Posted By  
 Question Submitted By :: Rasmi
I also faced this Question!!   © ALL Interview .com
Answer
Hi All,

This is sathish. Upto my knowledge you have three types of 
pointers in C.  They are

1)  Near
2)  Far
3)  Huge

Thanks & Regards
 
4
Sathish Kumar
 
 
Answer
Dear Satish... 
Can U explain in brief... please...

Thank You
 
0
Gg
 
 
Answer
According to size of program in code area,data area and
stack area there are six type of memory model:
1. Tiny
2. Small (default)
3. Medium
4. Compact
5. Large
6. Huge

Note: - to change memory model (in turbo c) go to
Option->compiler->code generation.
 
0
Ashwin Kumar
 
 
Question
Is the following code legal?
struct a
    { 
int x;
 struct a b;
    }
Rank Answer Posted By  
 Question Submitted By :: Guest
I also faced this Question!!   © ALL Interview .com
Answer
yes, it is nested structure
 
0
Dilpreet
 
 
Answer
no this code is illegal.

legal one:

struct a
{
int x;
struct a *b;
}
 
0
Raghu
 
 
Answer
This code is illegal.
 
0
Siva
 
 
Question
What's wrong with the call "fopen ("c:\newdir\file.dat", "r")"?
Rank Answer Posted By  
 Question Submitted By :: Tribhuvan Sharma
I also faced this Question!!   © ALL Interview .com
Answer
Hi All,

In the above function call fopen we should have used "C:\\" 
instead of using "C:\".  Because '\' is treated as a escape 
sequence.

Thanks & Regards
Sathish Kumar
 
0
Sathish Kumar
 
 
Question
How can I read a directory in a C program?
Rank Answer Posted By  
 Question Submitted By :: Tribhuvan Sharma
This Interview Question Asked @   Wipro , Bright Outdoor Pvt Ltd
I also faced this Question!!   © ALL Interview .com
Answer
In Linux/Unix , we have the header file dirent.h.This .h 
file contains the direcory manipulation functions Some of 
the functions are opendir,closedir,readdir.
 
0
Sathish
 
 
Question
How can I find out how much memory is available?
Rank Answer Posted By  
 Question Submitted By :: Tribhuvan Sharma
This Interview Question Asked @   Persistent
I also faced this Question!!   © ALL Interview .com
Answer
[root@server ~]# free
[root@server ~]# free -m
 
0
Pankajbisane
 
 
Question
How can I allocate arrays or structures bigger than 64K?
Rank Answer Posted By  
 Question Submitted By :: Tribhuvan Sharma
I also faced this Question!!   © ALL Interview .com
Answer
HI All,

In a book i studied that you can use far* to allocate 
memory above 64k limit.

Thanks & Regards
Sathish Kumar
 
0
Sathish Kumar
 
 
Answer
by using the pointers with the structures we can allocate the 
memory for the structure ,Pointers are DMA
 
0
Phani Kumar S
 
 
Answer
#include<stdio.h>
struct stud {
	int i,j,k;
	struct stud *next,*prev;
}**ptr;
void main(){
     int i;
      ptr= ( struct stud **)malloc(sizeof(struct stud*)*6400 );
      for(i=0;i<6400;i++)
	    ptr[i]= ( struct stud *)malloc(sizeof(struct stud)*10 );
}
 
0
DinakaranGct
 
 
Answer
Generally using the malloc() function maximum we can 
allocate the 64K memory.

If you want to allocate the memory larger than 64K then you 
have to use the farmalloc() memory management function.

And one more important thing is ,Once memory is allocated 
by the farmalloc(),then to free that memory we need to use 
only farfree() fuction.We can't use the free() fuction to 
free that memory.
 
0
S.v.prasad Reddy,lifetree
 
 
 
Back to Questions Page
 
 
 
 
 
   
Copyright Policy  |  Terms of Service  |  Help  |  Site Map 1  |  Articles  |  Site Map  |   Site Map  |  Contact Us interview questions urls   External Links 
   
Copyright © 2007  ALLInterview.com.  All Rights Reserved.

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