L-3: SSH, Autolab, Variables, Types, scanf #
Sandeep Nagar
Part-1
SSH, Autolab(pingala), pingala shell, Autograder
Part-2
Comments, Identifiers, Variables, Types, Constants, scanf, Controle Flow
L-3 Slides: https://cpro-iiit.github.io/docs/course_material/lectures/3/lec_3.pdf
Reference code: https://tinyurl.com/yuhchnuj
Programiz, web editor: https://tinyurl.com/bdd55vwn
What is SSH, and how do I use it? #
ssh sandeep.nagar@pingala.iiit.ac.in
- Connects to pingala server (at IIIT with Linux OS with all programs required for the course installed).
- Why?: All students will work in the same environment (os same, programs same, etc.)
Log in over SSH #
ssh user_name@pingala.iiit.ac.in
Enter your CAS password
You can work on the remote machine using your local computer.
You can edit, create, and copy files on the server.
Submit assessments using your local machine to Autolab.
Autolab: #
For automatic evaluation and grading of programs.
Two ways to submit for auto-grading:
pingala shell: using ssh shell (prefered)
GUI: user interface, using pingala.iiit.ac.in website
Questions about Autolab/ssh/pingala?
Running the Program on shell #
- Run gcc compiler to get the executable file
main
gcc main.c -o main
- Run the executable
main
./main
Comments for C: #
- Whole-line comment
- Partial line comment
- Multiple line comment
Programiz, web editor: https://tinyurl.com/bdd55vwn// This is a whole-line comment variable = 5; // this is partial line comment /* and comment comment .. */
Identifiers: #
- Unique names that are assigned to variables, structs, functions, and other entities.
- Allow us to name data and other objects in the program.
- Each identifier object in the computer is stored at a unique address.
Rules to create identifiers:
- First character must be alphabetical or underscore ‘_’
- Must contain only alphabetical characters, digits, or underscore
- The first 63 characters of an identifier are sufficient
- Can not duplicate a keyword
E.g. for identifiers #
a // valid
my_name // valid
_your_name_ // valid
_Bool // valid
_bool // valid but not same as _Bool
Student Name // invalid
int // not valid, int is a keyword
char // not valid, char is a keyword
2_name // invalid, starting with digit
I_am-Yoda // invalid, '-' not allowed
Constants: #
Constants are data values that can not be changed during the execution of a program. Like variables, constants have a type.
Constant types:
- Boolean, character, integer, real, complex, and string constants.
Variables: #
Void, Character, Integer
Variable Initialization: #
Character Types: #
// char, 1 byte (= 8 bit)
printf("%c", _char_)
Integer Types: #
short, int, long, long long
Size of integers
size of (short) ≤ size of (int) ≤ size of (long) ≤ size of (long long) 2 byte -> 4 byte = 4 byte -> 8 byte
Floating-point type: #
float, double, long double
size of (float) ≤ size of (double) ≤ size of (long double) 4 byte -> 8 byte -> 16 byte
Type summary: #
Type summary: #
Symbolic names for control characters #
Some common control characters along with their symbolic names:
1. Newline: `\n` printf("\n") 2. Horizontal tab: `\t` printf("\t") 3. Vertical tab: `\v` printf("\v") 4. Backspace: `\b` printf("\b") 5. Carriage return: `\r` printf("\r") 6. Form feed: `\f` printf("\f") 7. Alert (bell): `\a` printf("\a") 8. Backslash: `\\` printf("\\") 9. Single quote: `\'` printf("\'") 10. Double quote: `\"` printf("\"") 11. Question mark: `\?` printf("\?") 12. Null character: `\0` printf("\0")
scanf() #
- Function reads data from the standard input stream stdin into the given locations.
- Reads
format-string
from left to right
int a = 5; scanf("%d", &a);
scanf() #
scanf() #
scanf() #
Control Flow #
Condition is an expression (or series of expressions) e.g.
n < 3 or x < y || z < y
Operators Precedence and Associativity: some operations are done before others when evaluating an expression.
Parentheses: () // first Postfix operators: ++, -- Unary operators: +, -, !, ~, ++, --, (type) Multiplicative operators: *, /, % Additive operators: +, - Relational operators: <, >, <=, >= Equality operators: ==, != Logical AND operator: && Logical OR operator: || Assignment operators: =, +=, -= ... and so on // last
Associativity: #
When expressions contain operators of the same precedence level, their evaluation order is determined.
Left-Associative: operators are evaluated from left to right,
+
,+
- e.g.
a + b - c
will first evaluatea + b
and then subtractc
from the result.
- e.g.
Right-Associative: are evaluated from right to left, e.g.
=
- e.g.
a = b = c
,c
is assigned tob
, and then the resulting value ofb
is assigned toa
.
- e.g.
Crucial for correctly interpreting and writing C programming expressions.
Questions? #
Reading #
Next: Conditional Statements: if, else, while, switch, break, continue.
Chapter 3: Computer Science: A Structured Programming Approach Using C Behrouz A. Forouzan, Richard F. Gilberg
More about scanf : https://www.ibm.com/docs/en/i/7.4?topic=functions-scanf-read-data
Programiz, web editor: https://tinyurl.com/bdd55vwn
http://courses.washington.edu/mengr477/resources/Precedence.pdf