Question

# Define the board space for a four-dimensional Tic Tac Toe board? (in C#) What is harder...

1. Define the board space for a four-dimensional Tic Tac Toe board? (in C#)
2. What is harder creating the data structure you thought of or writing the rules that support it? Give a detailed example.
3. How do you pass a structure or an array to a function?
4. If I declare a variable as follows: int x; please describe how that variable is represented in memory. What does &(x) return? What does *(x) return? What does *(&(x)) return?

Define the board space for a four-dimensional Tic Tac Toe board?

Answer:- tic tcs toe is a very simple two player game. So only two players can play at a time. This game is also known as Noughts and Crosses game. In this game we have a board consisting of a 3*3 grid.

Game rule:-

• tradittionaly the first player plays with "X". so you can decide who wants to go "X" and who wants go with "O".
• only one player can play at a time
• if any of the players have filled a square then the other player and the same player can't override that square.
• the player that succeeds in placing three respective mark (X or O) in a horizontal, vertical or diagonal row wins the game.

Winning condition:-

Whoever places three respective marks(X or O) horizontally vertically or diagonally will be the winner.

How do you pass a structure or an array to a function?

Answer:- It can be done in below 3 ways:-

1. Passing structure to a function bt value.
2. Passing structure to a function by address(reference).
3. No need to a struture - Declare structure variable as global.
• A structure can be passes to any function from main function or from any sub function.
• Sturcutre definition will be availabe withi the function only.
• It won't be available to other functions unless it is passed to those funtions y value or by address(reference).
• Else, we have to declare structure variable as global variable. That mean, stucture variable should be declared outside the main function. So, this structre will be visible to all te functions in a C program.

If I declare a varibale as follows: int x; please describe how that variable is represent in memory.

Answer:- To represent variable ,we have to follow:-

• get the address and the size of the variable.
• typecast the address to the character pointer to get byte address.
• now loop for the size of the vaiable and print the value of typecasted pointer.

Example to represent variable"int x" in memory:-

#include <stdio.h>

typedef unsigned char *byte_pointer; //create byte pointer using char*

void disp_bytes(byte_pointer ptr, int len)

{ //this will take byte pointer, and print memory content

int i;

for (i = 0; i < len; i++)

printf(" %.2x," ptr[i]);

printf("\n");

}

void disp_int(int x)

{

disp_bytes((byte_pointer) &x, sizeof(int));

}

main() {

int i = 5;

disp_int(i);

}