12_c-prog - C-Programming Part 1 UCSD Physics 121 2008 Why...

Info icon This preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
C-Programming, Part 1 02/26/2008 Lecture 12 1 C-Programming Part I: basics prep. for Lab 8 Winter 2008 UCSD: Physics 121; 2008 2 Why C? C? See See http://www.scriptol.org/choose.php http://www.scriptol.org/choose.php and http://www.tiobe.com/tpci.htm +2.12% 2.528% 2.528% Ruby ± 10 20 20 10 +1.47% 2.982% 2.982% JavaScript JavaScript ± 10 10 9 -0.78% -0.78% 3.189% 3.189% C# C# ² 7 8 +0.90% 3.566% 3.566% Python ± 8 7 -0.63% -0.63% 6.073% 6.073% Perl = 6 6 -1.03% -1.03% 8.369% 8.369% (Visual) Basic (Visual) Basic ² 4 5 -0.07% -0.07% 8.847% 8.847% PHP ± 5 4 -0.53% -0.53% 10.768% C++ = 3 3 -2.23% -2.23% 16.104% C = 2 2 -3.45% -3.45% 18.978% Java = 1 1 ³ in last year year share Language movement 02/06 rank rank 02/07 rank rank Winter 2008 UCSD: Physics 121; 2008 3 C How it Stacks Up As U can C, the U can C, the C language (and its (and its extensions/derivatives ) dominates the software community Java also a strong showing Python worth a peek Advantages of C: compiled code runs FAST allows low-level device control a foundation of the programming world Disadvantages of C: strings are a pain in the @$$ awkward conventions (pointers can be difficult to learn) requires a compiler Winter 2008 UCSD: Physics 121; 2008 4 What we will and won What we will and won t do t do We will learn: to write simple programs basic interface control flow, math, printing data types enough to be dangerous We We won won t learn: t learn: advanced pointer operations large projects (linking separate programs) distinctions between public, private, external variables enough to be really dangerous
Image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
C-Programming, Part 1 02/26/2008 Lecture 12 2 Winter 2008 UCSD: Physics 121; 2008 5 C File Types Source Code the stuff you type in: has .c extension Compiled Compiled Executable Executable the ready-to-run product: usually no extension in Unix, .exe in DOS Header Files contain definitions of useful functions, constants: .h extension Object Files a pre-linked compiled tidbit: .o in Unix, .obj in DOS only if you’re building in pieces and linking later Winter 2008 UCSD: Physics 121; 2008 6 A typical (short) program Notes: first include is so we have access to printf (standard I/O) define the main program (must be called main ) to take no arguments (thus void ) and return an integer braces surround the program print value of integer, i , in formatted line return zero (common return value for successful program) #include <stdio.h> int main(void) { int i=53; printf(“The illustrious variable, i, is %d\n”,i); return 0; } Winter 2008 UCSD: Physics 121; 2008 7 More on program semicolons end each line within program spacing is not required, but makes for easier reading all variables must be declared before they are used could have simply said: int i; then declared later that i=53 ; – the \n is a newline; the %d formats as decimal integer #include <stdio.h> int main(void) { int i=53; printf(“The illustrious variable, i, is %d\n”,i); return 0; } Winter 2008 UCSD: Physics 121; 2008 8 Alternate form semicolons delimit separate statements, but this program, while compact, is harder on the eyes this time, we defined and assigned the variable in separate
Image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern