Showing posts with label C Programming Language. Show all posts
Showing posts with label C Programming Language. Show all posts

Friday, 4 January 2013

Matt Test

My erstwhile colleague Mr. Laver is sitting a Microsoft Certification test on Thursday, which he needs no luck at all to pass. While we were discussing a C bug problem, he introduced me to IDEOne, an online source code editor which has the novel feature of being able to embed the code into your own web site:


So... why does this code compile and run but the length function only produces zero no matter what string is input?

Friday, 14 December 2012

Return of C Test Part 2

... and I got 58.5 marks out of 61, 95%! Nice one!

For those interested, I managed to find some a unit test harness for C:

http://cunit.sourceforge.net

Careful with the spelling, chaps.

Pop quiz! Why does the following produce 47 rather than 144 (7 + 5)2? And what would you do to correct it?

#include <stdio.h>

#define FIRST_PART      7 
#define LAST_PART       5 
#define ALL_PARTS       FIRST_PART + LAST_PART 

int main() { 
    printf("The square of all the parts is %d\n", 
        ALL_PARTS * ALL_PARTS); 
    return (0);
}

Answers in the comments.

Tuesday, 11 December 2012

Return of C Test

Yep, folks, we've got another test this week on the C programming language. This time it's on arrays and strings (and pointers!!) so it's probably quite tricky. Wish me luck!

Oooo, a little test. Why won't this code compile properly?

#include <stdio.h>
char line[100];/* line of input data */
int  height;   /* the height of the triangle
int  width;    /* the width of the triangle */
int  area;     /* area of the triangle (computed) */

int main()
{
    printf("Enter width height? ");

    fgets(line, sizeof(line), stdin);
    sscanf(line, "%d %d", &width, &height);

    area = (width * height) / 2;
    printf("The area is %d\n", area);
    return (0);
}

Tuesday, 20 November 2012

Son of C Test Redux

Yesterday, the tutor of the C course went through the questions with us, as they were a little harder than last time. One of them was really tricky (and I didn't get it!):

1
2
3
4
5
#define MAX_COUNT 20
int counter;

for(counter = 0; counter < MAX_COUNT; counter++);
  printf("The value of the counter is %d\n", counter);

What's the output? (Answer in the comments)

Thursday, 15 November 2012

Son of C Test Part 2 - Caught By The Fuzz

I got a message from the tutor last night asking us to turn up early for the test this morning. The police and college security were going to do an airport-style security check and there might be a few delays as a result. It was all efficiently handled by the local (Metropolitan) Police. There was a stabbing at the college a few years back and the check is done every year. Looking for drugs as well, which they may have had more success with, by all accounts.

Coincidentally, we get to vote for the PCC today, as I blogged earlier, all of which gives me the excuse to show this:

Sorted!

The test itself was tougher than last time and I guessed at one question: How do you read in two variables using one scanf statement? Afterwards, I asked one of the other guys, Richard, who had the same answer and just tried it out on the compiler, and we got it right!

Update: I got 39... out of 45, 87%! Nice one!

Sunday, 11 November 2012

Son of C Test

Yes, folks, I've got another C Test on Thursday this week, so brown trousers at the ready.

As a test for all you C/C++/C#/Java people, what's the output of the following:
int i = 12;

if (i = 13){
  printf("Does this happen or not??");
}
(Yes, I know it's a mistake, but does it still work and what happens?)

Thursday, 18 October 2012

C Test - Part 2

...and I got 49.5.

Out of 52, which makes it 95.something percent, the highest mark I've ever got for anything, ever! So the SCJP wasn't a complete waste of time.

As an aside, the Pragmatic Programmer has been published, after a few years in eBook development hell:


A minor classic, I'm currently enjoying reading it.

Monday, 15 October 2012

C Test

I have my first assessment test today on the C programming language. ("You're wearing a nice pair of brown trousers, Mr Lemon!!").

Also, the K&R book, The C Programming Language by Brian Kernighan and Dennis Ritchie, is available next month from Pearson in eBook formats. A classic!

Oooo, here's a little puzzle for those of you who are C/C++/C#/Java developers. What's the output of the following:

int x = 10;
int y = 10;

printf("The value of x is %d and x++ is %d\n", x, x++);
printf("but the value of y is %d and ++y is %d\n", y, ++y);

Update: Got bowled a few fast ones but managed to field them quite well (I think!)

Monday, 17 September 2012

College Monday: Dev C++

Today I started my education in earnest with a class on software development. To teach us this, Bromley has decided to use C, which is the basis of quite a number of development languages. It's a fairly safe bet as C has been around since the early 1970's, taking off with the introduction of Microsoft's Visual C++, which, for a while, was the only way to make serious windows software.

We're using a package called Dev C++, which has an IDE written in (wait for it) Delphi 6. I kid you not. Wherever you go, there you are.


We've yet to get really into it: we've spent the lesson going over data types and functions are next month, so no rush then. I thought I'd show keeness by asking the lecturer if there were any exercises for us to do. He was mildly impressed.