// my first pointer
#include <iostream>
using namespace std;
int main ()
{
int firstvalue, secondvalue;
int * mypointer;
mypointer = &firstvalue;
*mypointer = 10;
mypointer = &secondvalue;
*mypointer = 20;
cout << "firstvalue is " << firstvalue << endl;
cout << "secondvalue is " << secondvalue << endl;
return 0;
}
firstvalue is 10
secondvalue is 20
Showing posts with label Programming. Show all posts
Showing posts with label Programming. Show all posts
Thursday, January 20, 2011
C Style of Substring
#include <string.h> /* for strncpy() */
#include <stdio.h> /* for printf() */
int
main(void)
{
char msg[] = "Hello World!";
char submsg[10]; /* Must be long enough */
/* Copy the substring "o W" from msg to submsg */
strncpy(submsg, &msg[4], 3);
/* Terminate the resulting string since strncpy() doesn't */
submsg[3] = '\0';
printf("msg[] = '%s'\nsubmsg[] = '%s'\n", msg, submsg);
return 0;
}
#include <stdio.h> /* for printf() */
int
main(void)
{
char msg[] = "Hello World!";
char submsg[10]; /* Must be long enough */
/* Copy the substring "o W" from msg to submsg */
strncpy(submsg, &msg[4], 3);
/* Terminate the resulting string since strncpy() doesn't */
submsg[3] = '\0';
printf("msg[] = '%s'\nsubmsg[] = '%s'\n", msg, submsg);
return 0;
}
Subscribe to:
Posts (Atom)