void main()
{
int a={1,2,3,4,5,6,7,8,9,10};
int *p=a;
int *q=&a;
cout<<q-p+1<<endl;
}
The output is 10, how?
if we give cout<<q it will print the address, value won't print....
if we give cout<<p it will print the address, value won't print....
p has the base addr; q... (1 Reply)
All ..
I am having a pointer array . And trying to store the addess into that pointer array . please see below the problem i faced
code:
int cnt1;
char *t_array;
char *f_array;
for(cnt1=0; cnt1<1000; cnt1++)
{
t_array =... (1 Reply)
If one wants to get a start address of a array or a string or a block of memory via a function, there are at least two methods to achieve it:
(1) one is to pass a pointer-to-pointer parameter, like:
int my_malloc(int size, char **pmem)
{
*pmem=(char *)malloc(size);
if(*pmem==NULL)... (11 Replies)
Hi all,
Can anyone provide help with getting the right syntax regarding array/pointers in C in the following code? Can't locate a specific example which clarifies this...
Say I declare a typedef to an array of pointers to some type...
/**
* An array of ptrs to sections
*/
typedef... (4 Replies)
if i create an array of pointers to a structure "struct node" as:
struct node *r;
and create "n" number of "linked lists" and assign it to the various struct pointers r using some function with a return type as structure pointer as:
r=multiplty(.......) /*some parameters*/
is... (2 Replies)
Hi guys,
Besides the points bellow, what would best practices for scripting be ?
1) set the PATH
2) unset the current environment (set -u ?)
3) (re)set the IFS to default value - space (IFS="" <- is this correct ?)
4) check the return code for each action inside the script (cd, rsync,... (1 Reply)
I am struggling with the pointer to 2D-array (cf: 2D array of pointers). Can anybody help me elaborate how the pointer x moves in the memory to access the individual of y, especially the high lighted lines?
I have talked to one of the curators of the forum, but I am still not quite clear.
Here... (1 Reply)
Discussion started by: yifangt
1 Replies
LEARN ABOUT PLAN9
getflags
GETFLAGS(9.2) GETFLAGS(9.2)
NAME
getflags, usage - process flag arguments in argv
SYNOPSIS
#include <libg.h>
#include <fb.h>
int getflags(int argc, char *argv[], char *flags)
int usage(char *tail)
extern char **flag[], cmdline[], *cmdname, *flagset[];
DESCRIPTION
Getflags digests an argument vector argv, finding flag arguments listed in flags. Flags is a string of flag letters. A letter followed by
a colon and a number is expected to have the given number of parameters. A flag argument starts with `-' and is followed by any number of
flag letters. A flag with one or more parameters must be the last flag in an argument. If any characters follow it, they are the flag's
first parameter. Otherwise the following argument is the first parameter. Subsequent parameters are taken from subsequent arguments.
The global array flag is set to point to an array of parameters for each flag found. Thus, if flag -x was seen, flag['x'] is non-zero, and
flag['x'][i] is the flag's ith parameter. If flag -x has no parameters flag['x']==flagset. Flags not found are marked with a zero. Flags
and their parameters are deleted from argv. Getflags returns the adjusted argument count.
Getflags stops scanning for flags upon encountering a non-flag argument, or the argument --, which is deleted.
Getflags places a pointer to argv[0] in the external variable cmdname. It also concatenates the original members of argv, separated by
spaces, and places the result in the external array cmdline.
Usage constructs a usage message, prints it on the standard error file, and exits with status 1. The command name printed is argv[0].
Appropriate flag usage syntax is generated from flags. As an aid, explanatory information about flag parameters may be included in flags
in square brackets as in the example. Tail is printed at the end of the message. If getflags encountered an error, usage tries to indi-
cate the cause.
EXAMPLES
main(int argc, char *argv[]){
if((argc=getflags(argc, argv, "vinclbhse:1[expr]", 1))==-1)
usage("[file ...]");
}
might print:
Illegal flag -u
Usage: grep [-vinclbhs] [-e expr] [file ...]
SOURCE
/sys/src/libfb/getflags.c
SEE ALSO ARG(2)DIAGNOSTICS
Getflags returns -1 on error: a syntax error in flags, setting a flag more than once, setting a flag not mentioned in flags, or running out
of arguments while collecting a flag's parameters.
GETFLAGS(9.2)