Hey guys,
Today's class seemed a little confusing to some.
Basically what he was saying is when your casting just take the type and put that in front of the pointer. Here's a simple example...
double example1(int, int, double);
int main()
{
/* Create pointer to a void type */
void (*p);
double holder = 0;
/*Cast pointer of void type to function type wanted */
p = (*(double (*)(int, int, double))p);
/*Let pointer be pointed to function start */
p = example1;
/*Run pointer and hold returned value */
holder = *p(2, 4, 5);
}
Wednesday, June 9, 2010
Thursday, June 3, 2010
Strings strings strings
Hey guys,
Todays class was interesting to say the least for the tangent Fardad went off on strings.
Basically:
char hello[50] = "hello everyones, how's it going"
where, the variable hello is compatible to the string "hello everyones, how's it going"
so that you can actually do the following:
printf("%c", "hello everyones, how's it going"[5]);
which is the same as,
printf("%c", hello[5]);
The string you put the variable equal are identical to each other in the usage aspect.
Monday, May 31, 2010
Lazy Evaluation
Hey again guys,
For those who missed the IRC class, I'll go over the quick lesson we were taught.
when do anything with an &&
if(a>3 && b>5)
OR
a>3 && printf("hello")
The part after '&&' will only be completed if the first part is true. Otherwise it skips the second part completely, aka lazy evaluation.
For those who missed the IRC class, I'll go over the quick lesson we were taught.
when do anything with an &&
if(a>3 && b>5)
OR
a>3 && printf("hello")
The part after '&&' will only be completed if the first part is true. Otherwise it skips the second part completely, aka lazy evaluation.
Saturday, May 22, 2010
Compiling Code for Platforms
In class we have learned how to only compile certain code when programming for multi-platforms.
Remember anything using the # sign talks directly with the compiler.
I will go over this just for a quick over view.
Remember anything using the # sign talks directly with the compiler.
In order to define the platforms, use the following format,
# DEFINE Linux 10
# DEFINE Windows 111
# DEFINE Mac 121
# DEFINE Platform Linux
After this is done, use the format
# if Platform=Linux /* Or any of the others */
/* do code */
# endif
/* Do for rest of platforms*/
Thursday, May 13, 2010
Answer and Explanation to Operand Example
Hey there fellow OOP344 students. Today's pop quiz thing went by pretty quick so I figured I'd show you guys the solution and explain it.
for(i=0;10>i; i++)
***ANSWER***
int main()
{
int i;
int n=0;
int j[10]={1,0,3,4,0,7,8,2,0,1};
{
n+=!j[i]; /*LINE OF CODE WANTED */
}
}
So in order to calculate the numbers of 0's within j's array [within one line], we must use the method taught today.
Firstly, remember 0 = FALSE, and 1 or greater than 1 = TRUE.
NOT (a number greater than 0) Returns FALSE; Aka NOT TRUE = FALSE.
so NOT (0) Returns TRUE; Aka NOT FALSE = TRUE.
So if the number in the array j[i] = 0, the expression !j[i] will become !0 Returns TRUE.
TRUE = 1, as we all should know.
So in conclusion, n+=1; adds one when j[i] = 0, adding all 0's.
If there is any confusion with the above, don't hesitate to ask me to try and clarify a bit more.
OOP344 at Seneca
Just started another semester at Seneca College. I'm taking a course called OOP344 which is pretty much advanced C++. Over the course of this semester I will be updating this blog on problems, solutions, and questions with regards to our text editor assignment we will be doing in groups.
Subscribe to:
Posts (Atom)