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  >>  Code Snippets  >>  Programming Code  >>  C Code
 
 


 

 
 C Code interview questions  C Code Interview Questions
 C++ Code interview questions  C++ Code Interview Questions
 VC++ Code interview questions  VC++ Code Interview Questions
 Java Code interview questions  Java Code Interview Questions
 Dot Net Code interview questions  Dot Net Code Interview Questions
 Visual Basic Code interview questions  Visual Basic Code Interview Questions
 Programming Code AllOther interview questions  Programming Code AllOther Interview Questions
Question
How to access command-line arguments?
 Question Submitted By :: Solidcube
I also faced this Question!!     Rank Answer Posted By  
 
  Re: How to access command-line arguments?
Answer
# 1
int main(int argc, char * argv[])
{
    //argc has count of no of arguments on command line.
    // argv[] contains array of strings seperated by space.
    // so argv[1] will give u, second argument, with first
    // argument being ur ./a.out(in unix)/test.exe(in win)
    // so this way u can access CL args.

    // ur code.
}
 
Is This Answer Correct ?    2 Yes 0 No
Hello
 
  Re: How to access command-line arguments?
Answer
# 2
int main(int argc,char *argv[])
{
	int i;
	for(i=0;i<argc;i++)
	cout<<argv[i];
}
 
Is This Answer Correct ?    2 Yes 0 No
Rakesh
 
 
 
  Re: How to access command-line arguments?
Answer
# 3
argc is nothing but Argument Count
argv is nothing Argument Vector (or) Argument Value which 
is array of Strings.

The first argument to the Command line is always the 
Program Name. 

argc contains no. of Arguments that it passed including the 
Program Name.So Leave the 1st Argument,

int i;
for(i=1;i<=argc;i++)
cout<<argv[i];
 
Is This Answer Correct ?    0 Yes 0 No
Pb
 
  Re: How to access command-line arguments?
Answer
# 4
By using -->
   int main(int argc, char * argv[])

In this statement the variable argc holds the at least one 
argument of type int , the name of the file it self first 
argument and *argv[] is array of char which takes the name 
of file.......
      If any correction plz E-mail me ...
                   Bye
 
Is This Answer Correct ?    0 Yes 0 No
Padmaraj
 

 
 
 
Other C Code Interview Questions
 
  Question Asked @ Answers
 
main() { int i; printf("%d",scanf("%d",&i)); // value 10 is given as input here }  1
main() { char *p = "hello world"; p[0] = 'H'; printf("%s", p); } a. Runtime error. b. “Hello world” c. Compile error d. “hello world” HCL1
print numbers till we want without using loops or condition statements like specifically(for,do while, while swiches, if etc)!  7
main() { printf("%x",-1<<4); }  1
1 o 1 1 0 1 0 1 0 1 1 0 1 0 1 how to design this function format in c-language ?  1
#include<stdio.h> main() { 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); }  1
#include<stdio.h> main() { struct xx { int x=3; char name[]="hello"; }; struct xx *s; printf("%d",s->x); printf("%s",s->name); }  1
main() { char *p; printf("%d %d ",sizeof(*p),sizeof(p)); }  1
main( ) { int a[2][3][2] = {{{2,4},{7,8},{3,4}},{{2,2},{2,3},{3,4}}}; printf(“%u %u %u %d \n”,a,*a,**a,***a); printf(“%u %u %u %d \n”,a+1,*a+1,**a+1,***a+1); }  1
main() { int i; float *pf; pf = (float *)&i; *pf = 100.00; printf("\n %d", i); } a. Runtime error. b. 100 c. Some Integer not 100 d. None of the above HCL1
void main () { int x = 10; printf ("x = %d, y = %d", x,--x++); } a. 10, 10 b. 10, 9 c. 10, 11 d. none of the above HCL1
#include <stdio.h> main() { char * str = "hello"; char * ptr = str; char least = 127; while (*ptr++) least = (*ptr<least ) ?*ptr :least; printf("%d",least); }  1
int i,j; for(i=0;i<=10;i++) { j+=5; assert(i<5); }  1
Given only putchar (no sprintf, itoa, etc.) write a routine putlong that prints out an unsigned long in decimal.  5
Sorting entire link list using selection sort and insertion sort and calculating their time complexity NetApp1
How to reverse a String without using C functions ? Wipro14
how to return a multiple value from a function? Wipro2
Program to Delete an element from a doubly linked list. Infosys4
Given an array of characters which form a sentence of words, give an efficient algorithm to reverse the order of the words (not characters) in it. Microsoft7
main() { int i; clrscr(); printf("%d", &i)+1; scanf("%d", i)-1; } a. Runtime error. b. Runtime error. Access violation. c. Compile error. Illegal syntax d. None of the above HCL1
 
For more C Code Interview Questions Click Here 
 
 
 
 
 
   
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