Donate to us via Paypal!
Imagination is more valuable than knowledge - Albert Einstein
Monday, March 01, 2021
Navigation
Home
 Find:
 Information:
Learn
Communicate
Submit
Shop
Challenges
 Exploit:
 Programming:
 Think:
 Track:
 Patch:
 Other:
 Need Help?
Other
Members Online
Total Online: 120
Guests Online: 120
Members Online: 0

Registered Members: 133766
Newest Member: denim6321d
Latest Articles

View Thread

HellBound Hackers | Computer General | Programming

Author

C Programming Assignment

Scar0ptics
Member



Posts: 229
Location: ∆ P®0X¥ W0R|D ∆
Joined: 19.11.13
Rank:
Mad User
Posted on 08-11-16 02:46
I thought I would share this for those who are interested Thumbs Up

List the output of the following code and explain it without using the compiler.

#include <stdio.h>

int main () {

int x [5];

x[0] = 100;
x[1] = 50;
x[2] = 25;
x[3] = 12;
x[4] = 6;

int *y = x;

printf("%d\n", *y+2);
printf("%d\n", *(y+2));
printf("%d\n", x[5]);
printf("%d\n", y);

}

2.) Create a Swap Function so that it correctly swaps two Integers and has the following output. Also include the call to the function in main. You must use pointers in your solution.

1,0
0,1

#include<stdio.h>

int main(int argc, char ** argv) {

int x = 0;
int y = 1;

printf("%d,%d\n", x,y);

// Swap Function

printf("%d,%d\n", x,y);

}


3.) Given the following Point Struct Create 5 points and chain them together using the next pointer, then print them out using a while loop.

Struct Point {
int x;
int y;
point *next;

}


*************************************************************************

Ill post the answers later.....

Edited by Scar0ptics on 15-11-16 13:01
overlay-network.ddns.net
Author

RE: C Programming Assignment

rex_mundi
☆ Lucifer ☆



Posts: 2018
Location: Scotland
Joined: 20.02.08
Rank:
God
Posted on 08-11-16 10:25
lol what's this for anyway ?
U N ⓡⓔⓧ_ⓜⓤⓝⓓⓘ
Author

RE: C Programming Assignment

Scar0ptics
Member



Posts: 229
Location: ∆ P®0X¥ W0R|D ∆
Joined: 19.11.13
Rank:
Mad User
Posted on 09-11-16 14:26
Its actually one of my assignments that I wanted to share.
overlay-network.ddns.net
Author

RE: Answers:

Scar0ptics
Member



Posts: 229
Location: ∆ P®0X¥ W0R|D ∆
Joined: 19.11.13
Rank:
Mad User
Posted on 15-11-16 00:05
1.)

printf("%d\n", *y+2); // 102
printf("%d\n", *(y+2)); //25
printf("%d\n", x[5]); //writes a random number out of system memory, as it is outside of what we implemented.
printf("%d\n", y); // writes a random number out of system memory, as it is outside of what we implemented.


2.) Create a Swap Function so that it correctly swaps two Integers and has the following output. Also include the call to the function in main. You must use pointers in your solution.

1,0
0,1

#include<stdio.h>

int main(int argc, char ** argv) {

int x = 0;
int y = 1;

void swap (int * _x, int * _Y);

printf("%d,%d\n", x,y);

swap(&x,&y);

printf("%d,%d\n", x,y);

}
// swap function
void swap (int * _x, * _y) {

int x = * _x;
int *_x = *_y;
int *_y = x;

}


3.) Given the following Point Struct Create 5 points and chain them together using the next pointer, then print them out using a while loop.

Struct Point {
int x;
int y;
point *next;

}

int main ( int argc, char **, argv) {

position a;
a.x = 100;
a.y = 200;

position a2;
a2.x = 1000;
a2.y = 2000;
a2.next = NULL;
a.next = &a2;

position a3;
a3.x = 10000;
a3.y = 20000;
a3.next = NULL;
a2.next = &a3;

position a4;
a4.x = 100000;
a4.y = 200000;
a4.next = NULL;
a3.next = &a4;

position a5;
a5.x = 1000000;
a5.y = 2000000;
a5.next = NULL;
a4.next = &a5;

position aa = &a;

while (AA != NULL) {

printf("%d,%d\n", aa->x, aa->y);
aa = aa->next;

}

}

Edited by Scar0ptics on 16-11-16 01:22
overlay-network.ddns.net